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-script
  • Create a new CosmWasm contract:

    cargo generate --git https://github.com/CosmWasm/cosmwasm-template.git --name my-contract
    cd my-contract
  • Compile the contract:

    cargo wasm
    cargo schema

Upload and Instantiate the Contract

  1. 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>
  2. 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>
  3. 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

  1. Create a Solidity file (MyContract.sol) in contracts/:

  2. Compile the contract:

Deploy the Smart Contract

  1. Create a deployment script (scripts/deploy.js):

  2. Deploy to Kiichain:

Interact with the Deployed Contract

  • Using Hardhat Console:


References

Last updated