Acquire the skills needed to understand and use RGB
The RLN project
rgb-lightning-node (RLN) project. This is a Rust daemon based on a fork of rust-lightning (LDK), modified to take into account the existence of RGB assets in a channel. When a channel is opened, the presence of RGB tokens can be specified, and each time the channel state is updated, a state transition is created that reflects the distribution of tokens in Lightning outputs. This enables :- Open Lightning channels in USDT, for example;
- Route these tokens through the network, provided the routing paths have sufficient liquidity;
- Exploit Lightning's punishment and timelock logic without modification: simply anchor the RGB transition in an additional output of the commitment transaction.
RGB protocol reminder
RGB-compatible Lightning node installation
rgb-lightning-node binary, we start by cloning the repository and its sub-modules, then we run the :git clone https://github.com/RGB-Tools/rgb-lightning-node --recurse-submodules --shallow-submodules
- The
--recurse-submodulesoption also clones the necessary sub-devices (including the modified version ofrust-lightning); - The
--shallow-submodulesoption restricts the depth of the clone to speed up downloading, while still providing access to essential commits.
cargo install --locked --debug --path .
--lockedensures that the version of dependencies is respected;--debugis not compulsory, but can help you focus (you can use--releaseif you prefer) ;--path .tellscargo installto install from the current directory.
rgb-lightning-node executable will be available in your $CARGO_HOME/bin/. Make sure this path is in your $PATH so you can invoke the command from any directory.Prerequisites
rgb-lightning-node daemon needs the presence and configuration of :- A
bitcoindnode
bitcoind to broadcast and monitor its on-chain transactions. Authentication (login/password) and URL (host/port) will need to be provided to the daemon.- An indexer (Electrum or Esplora)
- An RGB proxy
Regtest launch
regtest.sh script that automatically starts, via Docker, a set of services: bitcoind, electrs (indexer), rgb-proxy-server../regtest.sh start
- Create a
docker/directory to store ; - Run
bitcoindin regtest, as well as the indexerelectrsand thergb-proxy-server; - Wait until everything is ready to use.
# 1st shell rgb-lightning-node dataldk0/ --daemon-listening-port 3001 \ --ldk-peer-listening-port 9735 --network regtest # 2nd shell rgb-lightning-node dataldk1/ --daemon-listening-port 3002 \ --ldk-peer-listening-port 9736 --network regtest # 3rd shell rgb-lightning-node dataldk2/ --daemon-listening-port 3003 \ --ldk-peer-listening-port 9737 --network regtest
- The
--network regtestparameter indicates the use of the regtest configuration; --daemon-listening-portindicates on which REST port the Lightning node will listen for API calls (JSON);--ldk-peer-listening-portspecifies which Lightning p2p port to listen on;dataldk0/,dataldk1/are the paths to the storage directories (each node stores its info separately).
https:/rgb-lightning-node/
curl -X POST http://localhost:3001/address
bitcoind Regtest, we're going to mine a few bitcoins. Run :./regtest.sh mine 101
./regtest.sh sendtoaddress <address> <amount>
./regtest.sh mine 1
Testnet launch (without Docker)
rgb-lightning-node dataldk0/ --daemon-listening-port 3001 \ --ldk-peer-listening-port 9735 --network testnet rgb-lightning-node dataldk1/ --daemon-listening-port 3002 \ --ldk-peer-listening-port 9736 --network testnet rgb-lightning-node dataldk2/ --daemon-listening-port 3003 \ --ldk-peer-listening-port 9737 --network testnet
bitcoind_rpc_host:electrum.iriswallet.combitcoind_rpc_port:18332- indexer_url
:ssl://electrum.iriswallet.com:50013` proxy_endpoint:rpcs://proxy.iriswallet.com/0.2/json-rpc
bitcoind_rpc_username:userbitcoind_rpc_username:password
init/unlock API.Issuing an RGB token
curl -X POST -H "Content-Type: application/json" \ -d '{ "up_to": false, "num": 4, "size": 2000000, "fee_rate": 4.2, "skip_sync": false }' \ http://localhost:3001/createutxos
./regtest.sh mine 1
precision allows you to define the divisibility of the units.curl -X POST -H "Content-Type: application/json" \ -d '{ "amounts": [ 1000 ], "ticker": "Plan ₿ Academy", "name": "Plan ₿ Academy", "precision": 0 }' \ http://localhost:3001/issueassetnia
rgb:fc7fMj5S-8yz!vIl-260BEhU-Hj1skvM-ZHcjfyz-RTcWc10
Opening a channel and transferring an RGB asset
/connectpeer command. In my example, I control both nodes. So I'll retrieve the public key of my second Lightning node with this command:curl -X 'GET' \ 'http://localhost:3002/nodeinfo' \ -H 'accept: application/json'
031e81e4c5c6b6a50cbf5d85b15dad720fec92c62e84bafb34088f0488e00a8e94
Plan ₿ Academy). The /openchannel command lets you define the size of the channel in satoshis and opt to include the RGB asset. It depends on what you want to create, but in my case, the command is :curl -X POST -H "Content-Type: application/json" \ -d '{ "peer_pubkey_and_opt_addr": "031e81e4c5c6b6a50cbf5d85b15dad720fec92c62e84bafb34088f0488e00a8e94@localhost:9736", "capacity_sat": 1000000, "push_msat": 10000000, "asset_amount": 500, "asset_id": "rgb:fc7fMj5S-8yz!vIl-260BEhU-Hj1skvM-ZHcjfyz-RTcWc10", "public": true, "with_anchors": true, "fee_base_msat": 1000, "fee_proportional_millionths": 0, "temporary_channel_id": "a8b60c8ce3067b5fc881d4831323e24751daec3b64353c8df3205ec5d838f1c5" }' \ http://localhost:3001/openchannel
peer_pubkey_and_opt_addr: Identifier of the peer we wish to connect to (the public key we found earlier);capacity_sat: Total channel capacity in satoshis ;push_msat: Amount in millisatoshis initially transferred to the peer when the channel is opened (here I immediately transfer 10,000 sats so that he can make an RGB transfer later) ;asset_amount: Amount of RGB assets to be committed to the channel ;asset_id: Unique identifier of the RGB asset engaged in the channel;public: Indicates whether the channel should be made public for routing on the network.
./regtest.sh mine 6
Plan ₿ Academy tokens on node n°1's side. If node n°2 wishes to receive Plan ₿ Academy tokens, it must generate an invoice. Here's how to do it:curl -X POST -H "Content-Type: application/json" \ -d '{ "amt_msat": 3000000, "expiry_sec": 420, "asset_id": "rgb:fc7fMj5S-8yz!vIl-260BEhU-Hj1skvM-ZHcjfyz-RTcWc10", "asset_amount": 100 }' \ http://localhost:3002/lninvoice
amt_msat: Invoice amount in millisatoshis (minimum 3000 sats) ;expiry_sec: Invoice expiry time in seconds ;asset_id: Identifier of the RGB asset associated with the invoice ;asset_amount: Amount of RGB asset to be transferred with this invoice.
lnbcrt30u1pncgd4rdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4qv0grex9c6m22r9ltkzmzhddwg87eykx96zt47e5pz8sfz8qp28fgpp5jksvqtleryhvwr299qdz96qxzm24augy5agkdhltudk463lt9dassp5d6n0sqgl0c4gx52fdmutrdtqamt0y4xuz2rcgel4hpjwne08gmls9qyysgqcqpcxqzdylz5wfnkywnxvvmkvnt2x4fj6wre0gshvjtv95ervvzzg4592t2gdgchx6mkf5k45jrrdfn8j73d2f2xx4mrxycq7qzry4v4jan6uxhhacyqa4gn6plggwpq9j74tu74f2zsamtz6ymt600p8su4c4ap9g9d8ku2x3wdh6fuc8fd8pff2yzpjrf24ys3cltca9fgqut6gzj
Plan ₿ Academy token:curl -X POST -H "Content-Type: application/json" \ -d '{ "invoice": "lnbcrt30u1pncgd4rdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4qv0grex9c6m22r9ltkzmzhddwg87eykx96zt47e5pz8sfz8qp28fgpp5jksvqtleryhvwr299qdz96qxzm24augy5agkdhltudk463lt9dassp5d6n0sqgl0c4gx52fdmutrdtqamt0y4xuz2rcgel4hpjwne08gmls9qyysgqcqpcxqzdylz5wfnkywnxvvmkvnt2x4fj6wre0gshvjtv95ervvzzg4592t2gdgchx6mkf5k45jrrdfn8j73d2f2xx4mrxycq7qzry4v4jan6uxhhacyqa4gn6plggwpq9j74tu74f2zsamtz6ymt600p8su4c4ap9g9d8ku2x3wdh6fuc8fd8pff2yzpjrf24ys3cltca9fgqut6gzj" }' \ http://localhost:3001/sendpayment
curl -X 'GET' \ 'http://localhost:3001/listpayments' \ -H 'accept: application/json'
- A regtest environment (via
./regtest.sh) or testnet ; - A Lightning node (
rgb-lightning-node) based on abitcoind, an indexer and anrgb-proxy-server; - A series of JSON REST APIs for opening/closing channels, issuing tokens, transferring assets via Lightning, etc.
- Lightning engagement transactions include an additional output (OP_RETURN or Taproot) with the anchoring of an RGB transition;
- Transfers are made in exactly the same way as traditional Lightning payments, but with the addition of an RGB token;
- Multiple RLN nodes can be linked to route and experiment with payments across multiple nodes, provided there is sufficient liquidity in both bitcoins and asset RGB on the path.
Author
This tutorial has been written by Loïc Morel
You can say thanks by tipping the professor.
I write educational content about Bitcoin.
Credits
This tutorial has not been proofread yet
The original content has been translated by AI, but human review is necessary to ensure its accuracy.
2 939 sats1 470 sats735 satsEvery content on the platform is the result of a collaborative effort: each lesson, translation, and revision is made possible by the work of contributors. For this reason, we are always looking for proofreaders who can review our content in many languages. If you want to participate in the proofreading process, please reach out in our Telegram group and read our tutorial. We remind you that this content is open-source - licensed under CC BY-SA - so it can be freely shared and used, as long as the original source is credited.


