RGB Docs
  • RGB Protocol Documentation
  • Distributed Computing Concepts
    • Paradigms of Distributed Computing
    • Client-side Validation
    • Single-use Seals and Proof of Publication
  • Commitment layer
    • Commitment Schemes within Bitcoin and RGB
    • Deterministic Bitcoin Commitments - DBC
      • Opret
      • Tapret
    • Multi Protocol Commitments - MPC
    • Anchors
  • RGB State and Operations
    • Introduction to Smart Contracts and their States
    • Contract Operations
    • Components of a Contract Operation
    • Features of RGB State
  • RGB Contract Implementation
    • Contract Implementation in RGB
    • Schema
      • Schema example: Non-Inflatable Assets
    • Interface
      • Standard Interfaces by LNP/BP Association
      • Interface example: RGB20
    • Interface Implementation
  • RGB over Lightning Network
    • Lightning Network compatibility
  • Annexes
    • Glossary
    • Contract Transfers
    • Invoices
    • RGB Library Map
Powered by GitBook
On this page
  1. Annexes

Contract Transfers

PreviousGlossaryNextInvoices

Last updated 8 months ago

contractsIn this section we will be guided through a step-by-step RGB Contract Transfer operation, again with the cooperation of our cryptographic couple: Alice and Bob. We will also provide some coding sections of both our characters, which use the rgb Command Line Interface Tool which can be installed from the dedicated .

Let's start with Bob, who owns a Bitcoin wallet but has not yet started using RGB technology.

1) To begin operating with RGB protocol, Bob must install an RGB wallet. This startup process involves installing the RGB wallet software, which usually, by default, contains no contracts. The RGB wallet software, in addition, requires the ability to interact with Bitcoin UTXO through a Bitcoin wallet and a Bitcoin Blockchain node tool (a full node or an ). These tools are a mandatory requirement because, as we learned , are defined over Bitcoin UTXO and represent a necessary item for implementing transfers of contract in RGB.

2) Then, Bob has the task of acquiring the necessary information about the contracts. These data, in the RGB ecosystem, can be sourced through various channels, such as specific websites, e-mails, or Telegram messages, etc, following the 's choice. These data are distributed using a which is a data package containing , , , and .

Each of these parts, usually, consists of as little as 200 bytes of data, meaning a consignment is typically of the order of a few KiBs. The contract consignment can also be encoded in Base58 format and sent in a format similar to that of a PGP key or as a QR code. This kind of format In the future will also be easily adaptable to censorship-resistant transmission media such as Nostr, through the use of relay servers, or over the Lightning Network.

In this regards, it's useful to point out that the RGB ecosystem fosters innovation and competition among various wallets by allowing the freedom to propose new methods of contract interaction and transfer. This openness to experimentation and the adoption of new technologies, such as decentralized, censorship-resistant networks, promises to further enrich the capabilities offered by RGB.

3) Once a contract is obtained in consignment format, Bob is able to import it into his RGB wallet and validate the data contained herein. The next thing he can do is to find someone possessing the contract / asset he is interested in receiving in his wallet. In our example, Alice possesses the asset in her wallet. So, similarly to Bitcoin Transaction they can setup an RGB Transfer. The mechanism for discovering stakeholders who have owned states in the contract, such as Alice, remains up to the receiving party, just as the process for discovering who can pay in Bitcoin.

bob$ rgb invoice RGB20 100 <ContractId> tapret1st:456e3..dfe1:0
alice$ wallet construct tx.psbt
    • Spend Alice's single-use seal related to the asset being transferred.

alice$ rgb transfer tx.psbt <invoice> consignment.rgb

9) This terminal consignment, obviously larger than a contract consignment because of the inclusion of the entire history of the asset, is then forwarded to Bob, even though the related witness transition has not yet been broadcasted into the Bitcoin P2P Network.

10) Bob, at this point, using the rgb accept command proceeds at validating the transfer consignment. If the validation is successful:

  • Adds all the data to his stash.

  • Produce a signature of the validation process.

bob$ rgb accept consignment.rgb
sig:DbwzvSu4BZU81jEpE9FVZ3xjcyuTKWWy2gmdnaxtACrS # <— signature over consignment

11) After verifying the data contained in the transfer consignment handed over by Alice, Bob may optionally send to Alice the produced signature sig: to Alice, in a so-called payslip, which confirms her that Bob:

  • Agrees on the validity of the client-side validated data included in the consignment.

  • Agrees that the witness transaction shall be published.

12) Alice, by receiving the payslip:

  • May validate Bob's signature.

  • Publishes the witness transaction contained in the modified tx.psbt file using her wallet tool.

alice$ rgb check <sig>
alice$ wallet sign —publish tx.psbt

Once published, the witness transaction represents the conclusion of the transfer between Alice and Bob.

The following diagram represents a summary of all the operations just described:

Finally, the following diagram shows an example of transfer interaction between the various elements of the RGB technology stack composed of RGB wallets, RGB nodes, and Electrum Server.

Features of RGB Transfers

The approach adopted by RGB in transferring consignments between parties, as illustrated in the Alice and Bob example, underscores the significance of privacy and security.

In the ideal case, no one other than Bob and Alice is in possession of the consignment and witness transaction. Nonetheless, Bob has all the elements to verify the validity of the consignment by comparing it with the various anchors on the Bitcoin Blockchain. Bob's stash status is consequently updated through this consignment decomposition and validation procedure. In practical transfer cases, Alice may publish the witness transaction to be included in the blockchain only when some events have occurred, such as, for example, the transfer of some object from Bob.

In this regard, it's useful to point out that the RGB system offers a significant advantage over other digital exchange methods, especially when it comes to complex operations such as atomic swaps. Atomic swaps, commonly used in various cryptocurrency networks, such as the Lightning network, can present complications. Typically, they require two separate transactions and the use of a hash code to ensure that both parties complete the swap almost simultaneously. This process can create a situation where one party has the power to influence the timing of the exchange by revealing or withholding the hash code, which is known as the reverse American call option problem.

RGB simplifies this issue considerably. Instead of requiring two separate transactions, RGB allows the direct exchange of one asset against another (e.g., Bitcoin against an RGB asset or an RGB asset against another RGB asset) within a single transaction. This eliminates the need for a hash code, as both assets can be exchanged directly. If an exchange involves Bitcoin and RGB assets, both can be included in the same witness transaction output, making the process more direct and secure.

In addition, RGB introduces a mechanism that allows both parties to have complete control over the execution of the transaction. If the transaction is not published, both parties have the option to do so, ensuring that neither can take advantage at the expense of the other. If both parties fail to publish, the original inputs can be spent again, rendering the transaction invalid. This approach offers a higher level of security and flexibility than traditional methods while simplifying the exchange process.


4) In order to initiate a transition, Bob must act first. It does so by issuing an that calls the specific transfer method encoded in the of the contract and which he will hand over to Alice. This invoice generation, which precedes the effective asset transfer, guarantees that the invoice contains all the relevant instructions needed by Alice to make the transfer, containing in particular Bob's UTXO derived from his Bitcoin wallet encoded in or in clear. To generate the Invoice to be handled to Alice, he can use the rgb command line tool issuing a request e.g. over interface RGB20 an amount of 100 assets of a certain contact (for example 100 USDT), which will be to one of his identified by Txid and :vout using form, by typing the following code:

5) , which are described in more detail in this , are generated as simple URL strings and can be transmitted by any means in a manner similar to what we said for consignment.

6) Alice, who has both a Bitcoin wallet and an RGB wallet with a of client-side validated data, receive the Invoice from Bob, which appears to be a string like this:

rgb:2WBcas9-yjzEvGufY-9GEgnyMj7-beMNMWA8r-sPHtV1nPU-TMsGMQX/RGB20/100+utxob:egXsFnw-5Eud7WKYn-7DVQvcPbc-rR69YmgmG-veacwmUFo-uMFKFb , where Bob's UTXO has been blinded automatically in the generation process (for Invoice encoding see the ).

7) First, Alice prepares a transaction which spends the UTXO containing the which assigns the of the RGB asset to her. The following represents the generic shell command of a wallet utility in order to construct the transaction which will be modified later:

8) Then Alice, through a shell command, is now able to generate consignment.rgb that contains, according to the instruction of Bob's <invoice> :

The final RGB client-side data.

The history of state transitions since contract and contained in validated form in Alice's stash.

The unsigned version of the , elaborated from the tx.psbt file, which:

Contains in some first Opret / Tapret output the commitment related to the state transition to Bob, in addition to necessary "blank" state transitions if some additional assets where defined on the same single-use seal being spent by Alice.

related chapter
Electrum Server
RGB library
All the various possible channels for acquiring an RGB contract in the form of consignment in a wallet.
The transfer process begins with an invoice prepared by Bob which contains all the information that Alice needs to transfer the asset, in particular Bob's seal definition, encoded as a Blinded UTXO or in clear form.
Alice prepares a witness transaction including the information provided both by Bob's invoice and those coming from her RGB and Bitcoin wallet. In addition, through a transfer consignment allows Bob to verify all the asset history as well as the last state transition addressed to him.
Optionally Bob can sign a payslip which authorizes Alice to broadcast the witness transaction which marks the conclusion of the transfer between Alice and Bob
Transfer workflow diagram. The signature over consignment id can be optional.
The transfer process behind the scenes. It requires several round of interaction between the various components of the RGB stack.
Several channels to acquire an RGB contract in the wallet.
stash
PSBT
seal definition
ownership
terminal consignment
state transition
genesis
witness transaction
DBC
owned states
state transitions
contract issuer
contract consignment
Genesis
Schema
Interface
Interface Implementation
invoice
Schema
assigned
UTXOs
Tapret
Invoices
chapter
blinded form
previously