Skip to main content

State Transitions

Applies to both RGB lines

The idea is the same on both lines, but the structures, commands and files differ and can't be mixed. See Two RGB lines.

A state transition is a contract operation after genesis. It:

  • consumes owned state by closing its seals, which means spending the Bitcoin outputs that hold it;
  • creates new owned state, assigned to new seals (the recipient's and your change);
  • may add global state, which is append-only and is never modified or deleted;
  • is validated client-side: the contract's own code (AluVM) checks it, for example that amounts are conserved.

The transition itself never goes on chain. The transaction that spends the seals (the witness transaction) carries a 32-byte commitment to it, in an OP_RETURN output (opret) or in a taproot output (tapret), through a multi-protocol commitment. See Deterministic commitments. The recipient gets the transition and its history from the sender in a consignment and validates them.

Transitions aren't signed with holder keys. Closing a seal requires spending its output, so the Bitcoin signature on the witness transaction is what authorizes a transfer.

Before you broadcast
  • Send the consignment first. Give it to the recipient and let them validate or accept it before you publish the witness transaction. If the transaction is mined and the consignment is lost, the assets are lost.
  • Every allocation on a spent output must move. If an output you spend also holds state from another contract, the witness transaction has to carry a transition for that contract too, or that state is destroyed. rgb-lib, rgb-cmd and rgb-wallet do this for you. Don't build these transactions with your own coin selection.
  • Back up tapret wallets. A tapret commitment tweaks your output key. Without the RGB data directory, a seed-only wallet can't find or spend that output.

Line B​

From rgb-consensus src/operation/operations.rs:

// rgb-consensus 0.11.1
pub struct Transition {
pub ffv: Ffv,
pub contract_id: ContractId,
pub nonce: u64,
pub transition_type: TransitionType, // defined by the schema, e.g. NIA's `transfer`
pub metadata: Metadata,
pub globals: GlobalState, // new global state, if the schema allows it
pub inputs: Inputs, // the previous outputs (Opout) being consumed
pub assignments: Assignments<GraphSeal>,
pub signature: Option<Signature>, // optional issuer-style signature, used by PFA
}

There's no anchor or proof inside the transition. All transitions of one contract that a witness transaction closes seals for are grouped in a TransitionBundle. Bundles of different contracts share the transaction through the multi-protocol commitment. The schema decides which transitions exist. NIA, for instance, has only transfer, while IFA adds inflate, burn and link (rgb-schemas src/ifa.rs).

CLI flow​

StepWhoCommand
1Recipientrgb invoice --amount 100 <CONTRACT_ID>
2Senderrgb transfer <INVOICE> <CONSIGNMENT> <PSBT> writes the consignment and a PSBT that already contains the commitment
3Recipientrgb validate <CONSIGNMENT>
4SenderSign the PSBT with the key holder (for example bp-hot sign), then rgb finalize -p <PSBT> (-p publishes the transaction)
5RecipientAfter the transaction confirms, rgb accept <CONSIGNMENT> (the -f flag is ignored in 0.11.1)
rgb -d data1 -w rcpt1 invoice --amount 100 "$contract_id"
rgb -d data0 -w issuer transfer "$invoice" transfer.rgb transfer.psbt
rgb -d data1 -w rcpt1 validate transfer.rgb
bp-hot sign -N transfer.psbt wallets/0.derive
rgb -d data0 -w issuer finalize -p transfer.psbt transfer.tx
rgb -d data1 -w rcpt1 accept transfer.rgb

Each command also needs -n regtest --electrum=localhost:50001 or your own indexer. The full walkthrough is in Quick Start, and every flag is in the v0.11 CLI reference. In an app, rgb-lib's send and refresh do all of this, and move the consignment through an RGB proxy server. See Wallet integration.