Schema example: Non-Inflatable Assets
Last updated
Last updated
In this section, we will look more closely at an actual example of an RGB Contract Schema written in Rust and contained in the file from the . The Repository contains an example set of schema templates related to other types of contracts. This Schema, which we will be using as an example in this chapter, allows for the contract setup of Non-Inflatable Assets (NIA) that can be considered as the RGB analog to Ethereum's fungible tokens created with the ERC20 standard.
We can observe that a Schema can be divided into several general sections:
A header which contains:
An optional Root SchemaId
which indicates a limited form of inheritance from some master schema.
A reserved Feature
field which provides room for additional future extensions of contract schema.
A first section in which all the State Types and related variables (both pertaining to and ) are declared.
A second section where all the possible referencing the previously declared State Types are encoded.
A field containing the declaration of the Strict Type System being used in the whole schema.
A last section containing the validation scripts for all the operations.
After this layout indication, we provide below the actual Rust Code of the schema. Each code section is provided with a numbered reference to an explanation paragraph reported below.
(1) In this section:
ffv
statement indicates the version of the contract.
name
provides a human-readable identifier for the schema itself, although it provides no uniqueness guarantees
(2) In this section global_state
and its variables are declared, in particular:
GS_TERMS
containing some additional contract terms
such as a disclaimer.
GS_ISSUED_SUPPLY
which defines the initial supply of the token. In this case, since no inflation is allowed, it also represents the max supply.
The Once
statement guarantees that all these declarations are associated with a single value.
(4) This section of the contract schema marks the beginning of Contract Operations' declaration section. Starting from the operation allowed within genesis
:
No metadata
are declared.
The instantiation, inside the Genesis state, of all the variables of the Global State variables previously defined in code section (2).
The declaration of the first assignment(s)
of the token using the previously declared type OS_ASSET
. Note that the OnceOrMore
statement allows more than one allocation, in case the issuer wants to split the initial supply among multiple owners.
(5) The transitions
section provides the declaration of a single TS_TRANSFER
operation which:
Contains no metadata
.
Doesn't update the global state (it was defined only in Genesis).
Takes as inputs
at one or more assignments of type OS_ASSET
.
Allows to declare one or more assignments
of type OS_ASSET
.
Points to the AluVM
script that should be executed when validating operations of this type.
(6) A default assignment type is defined, to be used for example to pay an invoice that doesn't specify one.
The token's GS_NOMINAL
set of specifications which according to the contain: the token full name
, the ticker
, some additional details
, the digit precision
of the asset.
(3) In owned_type
section, through the OS_ASSET
statement, we can find the StateType declaration of the fungible token being transferred through the owned state assignment. The quantity of token used in the transfer is declared as a represented by a 64-bit unsigned integer. Additionally, we provide each assignment type with a default transition, which allows for instance to move it automatically to another seal when spending other allocations on the same UTXO.