Skip to main content

Rust

Applies to both RGB lines

Each line has its own crates, and they don't interoperate. See Two RGB lines.

Line B: v0.11Line A: v0.12
For wallets and appsrgb-lib 0.3.0-beta.7 (2026-07-17). The last non-beta, 0.2.2 (2023), is built on RGB 0.10 and works with neither line.rgb-runtime 0.12.0-rc.3, imported as rgbp
Lower levelrgb-api (imported as rgb), rgb-ops (rgbstd), rgb-consensus (rgbcore), rgb-schemas (schemata), all 0.11.1rgb-std 0.12.0-rc.3 (rgb), rgb-core 0.12.0
Minimum Rust1.85; rgb-lib needs 1.881.85
Chain accessElectrum or Esplora indexerElectrum or Esplora indexer

docs.rs failed to build rgb-api and rgb-ops 0.11.1, so the links above go to the source. Neither line needs a Bitcoin Core RPC connection. Pin every version exactly: Cargo never matches a pre-release such as 0.12.0-rc.3 from a plain "0.12". The crate called rgb on crates.io is an unrelated pixel-colour library.

Line B: rgb-lib​

rgb-lib (RGB-Tools) is a complete wallet: BDK for bitcoin, rgb-ops for RGB, SQLite for its database, and an RGB proxy server to exchange consignments. 0.3.0-beta.7 is built on rgb-ops 0.11.1-rc.11.

[dependencies]
rgb-lib = "=0.3.0-beta.7"
A new project doesn't resolve without rgb-lib's lock file

As of 2026-10-21, a fresh cargo build stops with failed to select a version for the requirement `secp256k1 = "^0.32.0-beta.2"` : rgb-consensus 0.11.1-rc.11, which rgb-lib pins, needs that version, and it has been yanked from crates.io. Cargo still uses a yanked version that is already in Cargo.lock, so start from rgb-lib's lock file. In your project directory, run curl -LO https://raw.githubusercontent.com/RGB-Tools/rgb-lib/0.3.0-beta.7/Cargo.lock before the first build.

The flow below uses only names that exist at the 0.3.0-beta.7 tag. It passes cargo check (2026-10-21, with that lock file), but wasn't run, because it needs an indexer and a proxy. The methods are on Wallet (src/wallet/singlesig.rs) and on the RgbWalletOpsOffline and RgbWalletOpsOnline traits.

// rgb-lib 0.3.0-beta.7
use std::collections::HashMap;

use rgb_lib::keys::{generate_keys, WitnessVersion};
use rgb_lib::wallet::{
DatabaseType, OnlineOptions, Recipient, RgbWalletOpsOffline, RgbWalletOpsOnline,
SinglesigKeys, Wallet, WalletData,
};
use rgb_lib::{AssetSchema, Assignment, BitcoinNetwork, Error};

const PROXY: &str = "rpc://127.0.0.1:3000/json-rpc";

fn demo(expiry: u64) -> Result<(), Error> {
let keys = generate_keys(BitcoinNetwork::Regtest, WitnessVersion::Taproot);
// Store keys.mnemonic securely. It is not enough to restore RGB assets on its own.
std::fs::create_dir_all("./data")?; // Wallet::new fails with InexistentDataDir otherwise
let mut wallet = Wallet::new(
WalletData {
data_dir: "./data".to_string(),
bitcoin_network: BitcoinNetwork::Regtest,
database_type: DatabaseType::Sqlite,
max_allocations_per_utxo: 1,
supported_schemas: vec![AssetSchema::Nia],
},
SinglesigKeys::from_keys(&keys, None),
)?;
let online = wallet.go_online(OnlineOptions {
indexer_url: "tcp://localhost:50001".to_string(),
skip_consistency_check: false,
vanilla_sync_lookback: 20,
})?;

// Fund wallet.get_address()? first, then create UTXOs to hold RGB allocations.
wallet.create_utxos(online, false, Some(5), None, 1, false)?;
let asset = wallet.issue_asset_nia("DEMO".into(), "Demo asset".into(), 0, vec![1000])?;

// The recipient (another Wallet) makes an invoice:
// rcv.blind_receive(None, Assignment::Fungible(100), expiry, vec![PROXY.into()], 1)?
// or rcv.witness_receive(...) for an address-based one.
let recipient_id = "<recipient_id from the invoice>".to_string();
let recipients = HashMap::from([(
asset.asset_id.clone(),
vec![Recipient {
recipient_id,
witness_data: None, // Some(WitnessData { .. }) for witness_receive invoices
assignment: Assignment::Fungible(100),
transport_endpoints: vec![PROXY.to_string()],
}],
)]);
wallet.send(online, recipients, false, 2, 1, expiry)?;

// Both sides call refresh until the transfer settles.
wallet.refresh(online, None, vec![], false)?;

// Encrypted backup of the whole RGB data directory.
wallet.backup("./wallet.backup", "backup password")?;
Ok(())
}

The rest of the API: list_assets, get_asset_balance, list_transfers, list_unspents, sync, send_begin/send_end with sign_psbt (for external signers), issue_asset_ifa/_uda/_cfa, and rgb_lib::wallet::restore_backup(path, password, target_dir). The Kotlin, Swift and Python bindings expose the same calls. The Node.js bindings cover a subset: at 0.3.0-beta.7 they have no issueAssetIFA, inflate or burn, and AssetSchema has no Ifa.

Use each wallet on one device only

The rgb-lib README warns that using the same mnemonic on more than one device "can lead to RGB asset loss due to improper UTXO management". rgb-lib expects to manage every UTXO of its wallet.

Line B: rgb-ops and rgb-api​

These are the crates rgb-cmd is built from. Use them for tooling, or for a wallet that manages its own bitcoin side.

[dependencies]
rgb-ops = { version = "=0.11.1", features = ["fs"] }
rgb-api = { version = "=0.11.1", features = ["bp", "fs"] } # or "bdk" for a BDK wallet
rgb-schemas = "=0.11.1"

rgb-api has no default features. Without bp or bdk it has no wallet backend for RgbWallet.

  • rgbstd::persistence::Stock holds contracts. Create it with Stock::in_memory() or Stock::load(provider, autosave). It has import_kit, import_contract, contract_builder(issuer, schema_id, chain_net), transition_builder(contract_id, name) and contract_wrapper::<NonInflatableAsset>(id) (the type is from rgb-schemas), which gives typed readers such as spec(), total_issued_supply() and allocations(filter) (src/persistence/stock.rs).
  • rgb::RgbWallet in rgb-api pairs a Stock with a bp-wallet or BDK wallet and provides pay, construct_psbt, transfer and history (src/wallet.rs).

Genesis has a complete ContractBuilder example that was compiled and run against rgb-ops 0.11.1. The rgb-schemas examples issue and read every schema. Line B 0.11.1 has no interfaces, valencies or state extensions.