The library provides tools and primitives to simplify the development of chain extensions for ink! and Substrate.
OBCE automatically generates everything needed to correctly call chain extension from ink! smart contracts, and to correctly implement the chain extension itself on the Substrate side.
OBCE' macros automatically generate all the logic related to argument encoding/decoding, function and extension identifier calculation and error handling.
The ink! side of OBCE is fully automated, while with Substrate all that's left is to implement the chain extension using generated traits.
In this tutorial we'll spin up our own Substrate node with rand-extension
enabled.
- Clone
substrate-contracts-node
repository. - Copy
examples/rand-extension/chain-extension
folder to a clonedsubstrate-contracts-node
repo and add it as a workspace member toCargo.toml
:
# ...
members = [
'chain-extension',
'node',
'runtime'
]
# ...
- Add
rand-extension
toruntime/Cargo.toml
:
rand-extension = { path = "../chain-extension", default-features = false, features = ["substrate"] }
Also, add rand-extension/substrate-std
to feature list that is activated
when std
feature is active:
[features]
# ...
std = [
# ...
"rand-extension/substrate-std",
]
- Launch node with
./target/debug/substrate-contracts-node --dev --tmp
. - Install
cargo-contract
using the installation guide. - Create new contract via
cargo contract new
command. - Replace
lib.rs
file with the one, that is provided inexamples/rand-extension
. - Modify contract's
Cargo.toml
to include chain extension as a dependency, and to activateink-std
feature ifstd
feature of a contract is enabled. ReplacePATH_TO_CHAIN_EXTENSION_CRATE
with the path torand-extension
crate:
[dependencies]
# ...
rand-extension = { path = "PATH_TO_CHAIN_EXTENSION_CRATE", default-features = false, features = ["ink"] }
[dev-dependencies]
# Include OBCE as a dev dependency to test the contract
obce = { git = "https://github.com/727-Ventures/obce", default-features = false, features = ["ink-std"] }
[features]
# ...
std = [
# ...
"rand-extension/ink-std"
]
- Build contract using
cargo contract build
. - Deploy contract using
cargo contract
or Contracts UI.
examples
directorypallet-assets