Smart Contracts
How to deploy smart contracts
Kiichain supports natively supports both CosmWasm and EVM smart contracts. Developers can choose between any of the two to create amazing dApps.
Working with Cosmwasm
Prerequisites
Install Rust and CosmWasm toolchain:
rustup default stable rustup target add wasm32-unknown-unknown cargo install cargo-generate --features vendored-openssl cargo install cargo-run-scriptCreate a new CosmWasm contract:
cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --name my-contract cd my-contractCompile the contract:
cargo wasm cargo schema
Upload and Instantiate the Contract
Store the Contract
kiichaind wasmd tx wasm store artifacts/my_contract.wasm --from my-key --gas auto --gas-adjustment 1.2 --node <KIICHAIN_NODE> --chain-id <KIICHAIN_CHAIN_ID>Instantiate the Contract
kiichaind wasmd tx wasm instantiate <CONTRACT_CODE_ID> '{}' --from my-key --label "My Contract" --gas auto --gas-adjustment 1.2 --node <KIICHAIN_NODE> --chain-id <KIICHAIN_CHAIN_ID>Execute the Contract
kiichaind wasmd tx wasm execute <CONTRACT_ADDRESS> '{"your_method": {}}' --from my-key --gas auto --gas-adjustment 1.2 --node <KIICHAIN_NODE> --chain-id <KIICHAIN_CHAIN_ID>
Working with EVM
Prerequisites
Install Node.js and Hardhat:
Install dependencies:
Write and Compile the Smart Contract
Create a Solidity file (
MyContract.sol) incontracts/:Compile the contract:
Deploy the Smart Contract
Create a deployment script (
scripts/deploy.js):Deploy to Kiichain:
Interact with the Deployed Contract
Using Hardhat Console:
References
CosmWasm Documentation: CosmWasm Docs
Ethereum Hardhat Guide: Hardhat Docs
Last updated