A Quick Example for Deployment using mantrachaind
This is a quick reference/demo of the deployment process for a developer to deploy, instantiate, and query a simple CosmWasm smart contact on the MANTRA DuKong Chain (Testnet).
The Smart Contract included in this demo is a very simple contract that stores the number of times the contract is "Poked".
Poke.wasm - about as simple as it gets - click here
- Instantiate: { counter: 0 }
- Query: { value: {} }
- Execute: { poke: {} }
Step 1. Download and extract the pre-built binary
On Linux:
# Download the CLI
curl -LO <https://github.com/MANTRA-Finance/public/raw/main/mantrachain-testnet/mantrachaind-linux-amd64.zip>
# Unzip the CLI
unzip mantrachaind-linux-amd64.zip
On MacOS:
# Download the CLI for Intel chips
curl -LO <https://github.com/MANTRA-Finance/public/raw/main/mantrachain-hongbai/mantrachaind-static-darwin-amd64.tar.gz>
# Download the CLI for Silicon chips (M1, M2...)
curl -LO <https://github.com/MANTRA-Finance/public/raw/main/mantrachain-hongbai/mantrachaind-static-darwin-arm64.tar.gz>
# Extract the CLI
tar -xzvf mantrachaind-static-darwin-*.tar.gz
Step 2. Setup Environment Variables
export CHAIN_ID="mantra-dukong-1"
export RPC="<https://rpc.dukong.mantrachain.io>"
# If you are using the bash terminal (usually Windows/Linux) add the following lines:
export NODE="--node $RPC"
export TXFLAG="$NODE --chain-id $CHAIN_ID --gas-prices 0.01uom --gas auto --gas-adjustment 1.5"
# Otherwise, if you are using zsh terminal (usually MacOS) add the following lines instead:
export NODE=(--node $RPC)
export TXFLAG=($NODE --chain-id $CHAIN_ID --gas-prices 0.01uom --gas auto --gas-adjustment 1.5)
Step 3. Add a Wallet
mantrachaind keys add wallet
Step 4. Get Some Tokens
You will need some OM test tokens stored in your wallet address in order to interact with the network. In order to get testnet tokens please request faucets at MANTRA Discord Server.
Check your balance mantrachaind query bank balances [YOUR WALLET ADDRESS] $NODE
Step 5. Deploy your Smart Contract Code
mantrachaind tx wasm store ./contract/poke.wasm --from wallet $TXFLAG -y --output json
Remember to take note of the the CodeId that is returned in the store_code event You can Query it using
mantrachaind query tx
[YOUR TX HASH] $NODEor
mantrachaind query tx [YOUR TX HASH] $NODE -o json| jq -r '.logs[0].events[] | select(.type == "store_code") | .attributes[] | select(.key == "code_id") | .value'
You can view your transaction using the hash returned e.g.
http://explorer.hongbai.mantrachain.io/mantrachain/transactions/[YOUR TX HASH]
Step 6. Create an instance of your Contract
mantrachaind tx wasm instantiate [YOUR CODE_ID] '{ "counter": 0 }' --from wallet --label "Poke Counter" $TXFLAG -y --no-admin
Remember to take note of the contract address from the _contract_address event
You can Query it
mantrachaind query tx [YOUR TX HASH] $NODE
or
mantrachaind query tx [YOUR TX HASH] $NODE -o json | jq -r '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address").value'
if you have jq installedYou can view your transaction using the hash returned e.g.
http://explorer.hongbai.mantrachain.io/mantrachain/transactions/[YOUR TX HASH]
Step 7. Interact with the Contract
Query the Poke Count
mantrachaind query wasm contract-state smart [YOUR CONTRACT ADDRESS] '{"value": {}}' $NODE
If you query the contact again, You should now see the counter "Value" has increased.
Last updated