Skip to main content

Interfaces, schemas and codexes

Applies to both RGB lines

Neither current line has the old interface API. Line B uses schemas with Rust wrappers, and Line A uses codexes, APIs and issuers. See Two RGB lines.

A short history​

Up to the v0.11 betas (the last, beta.9, came out in November 2024), RGB-WG's rgb-std had interfaces: Iface definitions named RGB20, RGB21 and RGB25, and IfaceImpl values that mapped an interface onto a schema, so a wallet could read any fungible contract the same way. Code from that period uses calls such as contract_iface_class::<Rgb20>().

Both lines dropped that design after the split:

  • Line B (rgb-ops 0.11.1) has no Iface types. A grep for IfaceImpl or contract_iface_class in rgb-ops, rgb-api and rgb-lib finds nothing. Line B names its contract types after their schemas (NIA, IFA, UDA, CFA, PFA) and treats "RGB20" and "RGB21" as deprecated names.
  • Line A (v0.12) replaced schemas and interfaces with codexes and APIs. The name RGB20 survives in issuer names such as RGB20-FNA, and an API can list the interface standards it conforms to.

Code or tutorials that use Iface, IfaceImpl or rgbstd::interface are for the old betas and won't compile against either line.

Line B: schemas and wrappers​

A schema defines a contract type: its global and owned state, its transitions and its AluVM validation scripts. The standard schemas are in rgb-schemas 0.11.1, and each comes as a compiled .rgb kit that a wallet imports. The Schemas guide covers the five standard schemas, their fields and their ids.

In place of interfaces, rgb-ops 0.11.1 (src/contract/schema.rs) has two traits:

  • IssuerWrapper, implemented by each schema type (NonInflatableAsset, InflatableFungibleAsset, UniqueDigitalAsset, CollectibleFungibleAsset, PermissionedFungibleAsset). It provides schema(), types(), scripts() and kit().
  • SchemaWrapper, implemented by the matching read-only view (NiaWrapper, IfaWrapper, …), which has typed getters such as spec(), contract_terms(), total_issued_supply() and allocations().

Reading a NIA contract, as in examples/nia.rs of rgb-schemas 0.11.1 (crates rgb-ops 0.11.1, imported as rgbstd, and rgb-schemas 0.11.1, imported as schemata):

use rgbstd::contract::FilterIncludeAll;
use schemata::NonInflatableAsset;

let contract = stock.contract_wrapper::<NonInflatableAsset>(contract_id)?;
let spec = contract.spec(); // ticker, name, precision
let supply = contract.total_issued_supply();
for alloc in contract.allocations(&FilterIncludeAll) {
println!("{} at {}", alloc.state.value(), alloc.seal);
}

Stock::contract_wrapper is in src/persistence/stock.rs. Apps built on rgb-lib don't touch these traits: rgb-lib embeds the NIA, UDA, CFA and IFA schemas and exposes assets through its own API.

Further reading​