Crate pop_contracts
source ·Expand description
§pop-contracts
A crate for generating, building, deploying, and calling ink! Smart Contracts. Used by pop-cli.
§Usage
Generate a new Smart Contract:
use pop_contracts::create_smart_contract;
let name = '...';
let contract_path = ...;
create_smart_contract(name, &contract_path)?;Build an existing Smart Contract:
use pop_contracts::build_smart_contract;
let contract_path = ...;
let build_release = true; // `true` for release mode, `false` for debug mode.
build_smart_contract(&contract_path, build_release)?;Test an existing Smart Contract:
use pop_contracts::{test_e2e_smart_contract, test_smart_contract};
let contract_path = ...;
//unit testing
test_smart_contract(&contract_path)?;
//e2e testing
test_e2e_smart_contract(&contract_path)?;Deploy and instantiate an existing Smart Contract:
use pop_contracts::{ instantiate_smart_contract, set_up_deployment, UpOpts};
// prepare extrinsic for deployment
let up_opts = UpOpts {
path: ...,
constructor: ...,
args: ...,
value: ...,
gas_limit: ...,
proof_size: ...,
salt: ...,
url: ...,
suri: ...,
}
let instantiate_exec = set_up_deployment(up_opts);
let contract_address = instantiate_smart_contract(instantiate_exec, Weight::from_parts(gas_limit, proof_size))
.await
.map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?;If you don’t know the gas_limit and proof_size, you can perform a dry run to estimate the gas amount before instatianting the Smart Contract:
use pop_contracts::{ instantiate_smart_contract, dry_run_gas_estimate_instantiate};
let weight_limit = match dry_run_gas_estimate_instantiate(&instantiate_exec).await?;
let contract_address = instantiate_smart_contract(instantiate_exec, weight_limit)
.await
.map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?;Call a deployed (and instantiated) Smart Contract:
use pop_contracts::{set_up_call, CallOpts};
// prepare extrinsic for call
let call_opts = CallOpts {
path: ...,
contract: ...,
message: ...,
args: ...,
value: ...,
gas_limit: ...,
proof_size: ...,
url: ...,
suri: ...,
execute: ...,
}
let call_exec = set_up_call(call_opts).await?;For operations that only require reading from the blockchain state, it does not require to submit an extrinsic:
use pop_contracts::dry_run_call;
let call_dry_run_result = dry_run_call(&call_exec).await?;For operations that change a storage value, thus altering the blockchain state, requires to submit an extrinsic:
use pop_contracts::call_smart_contract;
let url = ....;
let call_result = call_smart_contract(call_exec, Weight::from_parts(gas_limit, proof_size), url)
.await
.map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?;Same as above, if you don’t know the gas_limit and proof_size, you can perform a dry run to estimate the gas amount before calling the Smart Contract:
use pop_contracts::{ call_smart_contract, dry_run_gas_estimate_call};
let url = ....;
let weight_limit = match dry_run_gas_estimate_call(&call_exec).await?;
let contract_address = call_smart_contract(call_exec, weight_limit, url)
.await
.map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?;§Acknowledgements
pop-contracts would not be possible without the awesome crate: cargo-contract.
Structs§
- Attributes for the
callcommand. - Attributes for the
upcommand
Functions§
- Build the smart contract located at the specified
pathinbuild_releasemode. - Call a smart contract on the blockchain.
- Create a new smart contract.
- Simulate a smart contract call without modifying the state of the blockchain.
- Estimate the gas required for a contract call without modifying the state of the blockchain.
- Estimate the gas required for instantiating a contract without modifying the state of the blockchain.
- Instantiate a contract.
- Checks if the specified node is alive and responsive.
- Parse hex encoded bytes.
- Runs the latest version of the
substracte-contracts-nodein the background. - Prepare the preprocessed data for a contract
call. - Prepare
InstantiateExecdata to upload and instantiate a contract. - Run the e2e tests of a smart contract.
- Run unit tests of a smart contract.