Deployment and Interaction
Deployment on the STRAI Chain can be performed in two ways, depending on your operating system compatibility and preferred development approach. These methods are as follows:
From the previous section, we have the wasm binary ready. Now it is time to deploy it on Testnet and start interacting. You can use the straichaind CLI or the CosmJS Node Console as you prefer. straichaind 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.
straichaind query wasm list-code $NODE
Here is an alternative if you haven't set up the environment variables to interact with the network previously:
straichaind query wasm list-code --node
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=$(straichaind 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=$(straichaind tx wasm store artifacts/cw_nameservice.wasm --from wallet --node -chain-id strai-testnet-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=$(straichaind query tx $TX_HASH --node -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.
straichaind query wasm list-contract-by-code $CODE_ID --node --output json
The response should be an empty list as we have not instantiated any contract yet.
{"contracts":[],"pagination":{"next_key":null,"total":"0"}}
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.
Download the wasm binary from the chain and compare it to the original one
straichaind query wasm code $CODE_ID --node download.wasm
The two binaries should be identical, and the diff
command should return nothing
diff
command should return nothingdiff artifacts/cw_nameservice.wasm download.wasm
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.
Prepare the instantiation message
INIT='{"purchase_price":{"amount":"100","denom":"uom"},"transfer_price":{"amount":"999","denom":"uom"}}'
Instantiate the contract
straichaind tx wasm instantiate $CODE_ID "$INIT" --from wallet --label "name service" $TXFLAG -y --no-admin
Check the contract details and account balance
straichaind query wasm list-contract-by-code $CODE_ID $NODE --output json CONTRACT=$(straichaind query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[-1]') echo $CONTRACT
See the contract details
straichaind query wasm contract $CONTRACT $NODE
Check the contract balance
straichaind query bank balances $CONTRACT $NODE
Upon instantiation the cw_nameservice contract will store the instantiation message data in the contract's storage with the storage key "config".
Query the entire contract state
straichaind query wasm contract-state all $CONTRACT $NODE
Last updated