Deployment and Interaction

Deployment on the MANTRA Chain can be performed in two ways, depending on your operating system compatibility and preferred development approach. These methods are as follows:

Using mantrachaind

In this method, the instantiation and interaction with the binary are done using the mantrachaind CLI or the CosmJS Node Console, which results in deploying CW contracts on-chain. Refer to this section for understanding the deployment and interaction with the chain. Additionally, see the section “A Quick Example for Deployment Using mantrachaind” for deploying the contract on the DuKong Testnet with the poke.wasm example.

Using TypeScript

This approach utilizes cosmwasm-tools and ts-codegen, which let you generate TypeScript classes for your contracts' interaction and on-chain deployment. Refer to the section “Deployment Using TypeScript (Windows/Linux/Mac)” below to set up your development environment and deploy your contracts on the DuKong Testnet.

From the previous section, we have the wasm binary ready. Now it is time to deploy it on DuKong and start interacting. You can use the mantrachaind CLI or the CosmJS Node Console as you prefer.

mantrachaind CLI

Let's deploy the code to the blockchain. Once that is complete, you can download the bytecode to verify it.

See the list of codes that was uploaded to the network previously.

mantrachaind query wasm list-code $NODE
# Here is an alternative if you haven't set up the environment variables to interact with the network previously:
mantrachaind query wasm list-code --node <https://rpc.dukong.mantrachain.io:443>

Now let us store the bytecode onchain and acquire the Code Id. The Code Id will later be used to create an instance of the cw_namespace contract.

# If you have already set up the environment variables, you can use the following command:
RES=$(mantrachaind tx wasm store artifacts/cw_nameservice.wasm --from wallet $TXFLAG -y --output json)
# Otherwise, you will have to type in the following command to upload the wasm binary to the network:
RES=$(mantrachaind tx wasm store artifacts/cw_nameservice.wasm --from wallet --node <https://rpc.dukong.mantrachain.io:443> --chain-id mantra-dukong-1 --gas-prices 0.01uom --gas auto --gas-adjustment 2 -y --output json)
# The response contains the Code Id of the uploaded wasm binary.
echo $RES

# Get the Transaction Hash from the response
TX_HASH=$(echo $RES | jq -r .txhash)

# Get the full transaction details with events 
CODE_ID=$(mantrachaind query tx $TX_HASH --node <https://rpc.dukong.mantrachain.io:443> -o json| jq -r '.logs[0].events[] | select(.type == "store_code") | .attributes[] | select(.key == "code_id") | .value')

echo $CODE_ID

Let's see the list of contracts instantiated using the Code Id above.

The response should be an empty list as we have not instantiated any contract yet.

Before we instantiate a contract with the Code Id and interact with it, let us check if the code stored on the blockchain is indeed the cw_namespace.wasm binary we uploaded. This step is optional.


Instantiating the Contract

We can now create an instance of the wasm contract. Following the instantiation, we can make queries and this time receive non-empty responses.


Contract Interaction

Now that the contract is instantiated, let's register a name and transfer it to another address by paying the transfer fee.


CosmJS Node Console

The binary can be deployed to the chain, instantiated and interacted with using the CosmJS Node Console as well.

Open a new Terminal window and initialize a CosmJS CLI session with the following command:

Now, let's import the necessary utilities, generate a wallet address, and deploy the wasm binary to the blockchain.

Please note the codeId of the uploaded wasm binary. This is the codeId that will be used to instantiate the contract.

You may compare the value of originalChecksum with the contents of the file artifacts/checksums.txt to make sure the code on the chain is identical to the cw_nameservice.wasm binary.

For future reference, you may get the checksum for a given Code Id as follows:

You may then compile the contract code yourself, optimize the resulting binary and compare the checksum to the value of hash to make sure the code on the chain was not tampered with.

Instantiating the Contract

Now, the wasm binary is uploaded to the chain with a Code Id and is ready to be instantiated.

First define a defaultFee to be passed into instantiation and execution functions later on:

Create a cw_nameservice contract instance using the code id we have received upon upload.

We've successfully instantiated the contract and have a contract address for the new instance.

The list of contracts instantiated using a certain codeId can be queried using the following command:

Contract Interaction

Now let us register a name on the nameservice contract instance and transfer it to another address.

Query the name record to see the owner address.

Now, let us create another wallet and transfer the ownership of the name to the new wallet address.

Query the name record one more time to see the address for the new owner.

Last updated