rootchain-std
The standard library for developing RootChain smart contracts.
rootchain-std is the developer-facing toolkit for authoring on-chain programs that run inside the RootChain WASM virtual machine. It provides safe, ergonomic access to host functions (state storage, events, caller context), token standards (RRC-20, RRC-721), and the #[rootchain_contract] macro.
What's Inside
| Module | Description |
|---|---|
traits |
RRC-20 and RRC-721 token standard trait definitions |
rrc721 |
Base implementation for Non-Fungible Token collections |
types |
Contract-local types (e.g., TokenId) |
error |
ContractError type for safe error handling |
lib |
Host function bindings: state_get, state_set, get_caller, log_event, set_metadata |
Installation
[]
= { = "1.0.2", = false }
Note: Always use
default-features = falsefor production contracts. Thestdfeature enables the full standard library, which is not available in WASM.
Enable the test-utils feature to use in-memory mock host functions during unit testing:
[]
= { = "1.0.2", = ["test-utils"] }
Writing a Contract
1. Define Your Contract
extern crate alloc;
use ;
2. Access Host Functions
use ;
// Read ABI-encoded input from the VM
let input = read_input;
// Write output back to the VM
write_output;
// Emit a structured event (indexed by topic hashes)
let topic = Hash;
log_event;
3. State Management
// State is accessed via raw host function calls
// The rootchain_std::storage module provides typed helpers
unsafe
Token Standards
RRC-20 (Fungible Tokens)
Implement the RRC20 trait to create a fungible token compatible with the RootChain explorer and wallet.
RRC-721 (Non-Fungible Tokens)
Implement the RRC721 trait or extend BaseRRC721 from rootchain_std::rrc721 for an NFT collection.
License
MIT — See LICENSE for details.