Hongbai Deployment and Interaction

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 Hongbai 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: {} }

For more detailed information visit the online documentation at https://docs.mantrachain.io

Quick Reference

  • RPC Endpoints: https://rpc.hongbai.mantrachain.io

  • API Endpoints: https://api.hongbai.mantrachain.io

  • Faucet: http://faucet.hongbai.mantrachain.io

  • Explorer: http://explorer.hongbai.mantrachain.io


Step 1. Download and Unzip the Pre-Built binary (Linux)

# Download the CLI
curl -LO https://github.com/MANTRA-Finance/public/raw/main/mantrachain-hongbai/mantrachaind-linux-amd64.zip

# Unzip the CLI
unzip mantrachaind-linux-amd64.zip

NOTE: If you get an error when running the CLI missing libwasmvm.x86_64.so then you need to download the lib by running: sudo wget -P /usr/lib https://github.com/CosmWasm/wasmvm/releases/download/v1.3.1/libwasmvm.x86_64.so

If you are using the dev container in this repository then this is already installed.

Step 2. Setup Environment Variables

export CHAIN_ID="mantra-hongbai-1"
export RPC="https://rpc.hongbai.mantrachain.io"
export NODEARG="--node $RPC"
export TXFLAG="$NODEARG --chain-id $CHAIN_ID --gas-prices 0.0001uom --gas auto --gas-adjustment 2"

Step 3. Add a Wallet

mantrachaind keys add wallet

Remember to save the address and the mnemonic

Step 4. Get Some Tokens

http://faucet.hongbai.mantrachain.io/

Check your balance mantrachaind query bank balances [YOUR WALLET ADDRESS] $NODEARG

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 mantrachaind query tx --type hash [YOUR TX HASH] $NODEARG

or mantrachaind query tx --type hash [YOUR TX HASH] $NODEARG -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 --type hash [YOUR TX HASH] $NODEARG

or mantrachaind query tx --type hash [YOUR TX HASH] $NODEARG -o json | jq -r '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address").value' if you have jq installed

You 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": {}}' $NODEARG

e.g. mantra1m7wqgq02e95anl7jk2qruvtdl7afyff0d6pddr0zhqmgsvle70ls7aa2ws

"Poke" the Contract

mantrachaind tx wasm execute [YOUR CONTRACT ADDRESS] '{"poke":{}}' --amount 100uom --from wallet $TXFLAG -y

If you query the contact again, You should now see the counter "Value" has increased.

Last updated