ChainX

How to Deploy ChainX Smart Contract

ChainX Smart Contracts

Run node

1. Accessing the test network

2. Running local nodes

Substrate Contracts, the Smart Contract Platform on ChainX

Gas related parameters

Schedule {
Version: 0, // configuration version
Put_code_per_byte_cost: 200, // Gas required per byte when setting the wasm code
Grow_mem_cost: 1, // Gas needed for memory increment in a single page
Regular_op_cost: 1, // Gas needed by the ordinary operator Op
Return_data_per_byte_cost: 1, // Gas consumed by return value per byte. The value should be carefully designed for the interoperability of contracts.
Event_data_per_byte_cost: 20, // Gas consumed by event per byte in the contract
Event_per_topic_cost: 1, // Gas consumed by each topic of event
Event_base_cost: 1, // the base Gas consumed by each event in the contract, for example, Gas got reduced every time an event is executed.
Call_base_cost: 60000, // the base Gas consumed by calling contracts, to put it in another word, Gas got reduced every time when a contract function is called.
Instantiate_base_cost: 200000, // the base Gas consumed when a contract is initialized (instantiated)
Sandbox_data_read_cost: 1, // Gas consumed by reading a byte in the contract
Sandbox_data_write_cost: 1, // Gas consumed by writing a byte in the contract
Max_event_topics: 4, // the maximum number of events in a single call
Max_stack_height: 64 * 1024, // the maximum value of the stack in the contract
Max_memory_pages: 16, // the maximum number of pages in the contract execution
Max_table_size: 16 * 1024, // the maximum number of data structure tables in the contract
Enable_println: false, // whether print is enabled in the contract
Max_subject_len: 32, // maximum number of PRNG subjects
}

Developing and debugging contracts

Some unexpected errors

tail -f log/chainx.log | egrep "xcontracts|apply_extrinsic"

1. Contract code setting related issues

[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: there is not enough gas for storing the code
[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: Can't decode wasm code
[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: the code is already stored on chain
[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: module imports `ext_println` but debug features disabled

2. Contract code deployment related issues

[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: Alive contract or tombstone already exists
Hash(code_hash + hash(input_data) + deployer)
[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: during execution|Failed to invoke an exported function for some reason|wrong selector, decode params fail or inner error

3. Contract code call related issues

[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: during execution|Failed to invoke an exported function for some reason|wrong selector, decode params fail or inner error
Struct Incrementer {
Value: storage::Value<u32>,
}
Impl Deploy for Incrementer {
Fn deploy(&mut self) {
// not init value
}
}
Impl Incrementer {
/// Flips the current state of our smart contract.
Pub(external) fn inc(&mut self, by: u32) {
// see this in the log
Env.println(&format!("Incrementer::inc by = {:?}", by));
Self.value += by; // call uninitialized storage
}
}
[runtime|chainx_runtime::xexecutive|183L] [apply_extrinsic] failed: during execution|Failed to invoke an exported function for some reason|reach gas limit
[runtime|xrml_xcontracts::gas] [refund_unused_gas]|account:88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee (5SjUJPJJ...)|gas_payment:2500000|refund:0|real cost:2500000|gas_spent:500000

Inter-chain assets in ChainX’s smart contracts

ChainX’s bitcoin X-BTC

XRC20 on ChainX

ChainX wallet supports XRC20 abi

Main network and test network

ChainX Dev nodes

Wallet function

Deployment and Testing of ChainX’s Smart Contracts

About ChainX

ChainX is the largest Layer-2 network of Bitcoin, based on Substrate, and will evolve into the Polkadot Secondary Relay Chain.