This sample is not compatible with the latest release of Substrate because the APIs have evolved quite a bit. The repo is being archived for the same reason. Please do not use this sample. The underlying APIs in Substrate have been replaced by chain extensions and contract-to-runtime interaction is possible with that - paritytech/substrate#9276
A sample Substrate runtime showing interaction between runtime modules (pallets) and smart contracts (ink!).
In the template module (pallet) in the runtime, following funtions are used for contract interaction:
- call_contract
- get_contract_storage
In the custom_type contract, the read_custom_runtime
funtion is used to query the runtime storage for a custom struct.
{
"Foo": {
"id": "u32",
"data": "Vec<u8>"
}
}
Keys to storage items in substrate runtime are constructed by hashing the raw key.
Refer to the substrate documentation about storage types and key construction.
Install Rust:
curl https://sh.rustup.rs -sSf | sh
Initialize your Wasm Build environment:
./scripts/init.sh
Build Wasm and native code:
cargo build --release
Install Cargo Contract:
cargo install --force --git https://github.com/paritytech/cargo-contract
Inside the contracts/custom_type
sub-directory, run the following commands to build the contract and generate its metadata:
cargo +nightly contract build
cargo +nightly contract generate-metadata
Start a development chain with:
./target/release/substrate-runtime-contract-sample --dev
Detailed logs may be shown by running the node with the following environment variables set: RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev
.
Additional CLI usage options are available and may be shown by running cargo run -- --help
.
Once the Substrate node is running, deploy and instantiate the contract using the Polkadot JS portal.