Skip to main content
Version: 0.16

Uploading and Interacting

We have the binary ready. Now it is time to see some wasm action. You can use Go CLI or Node Console as you wish.

Go CLI#

We generated a wasm binary executable in the previous chapter. Let's put it into use. Now, we will upload the code to the blockchain. Afterwards, you can download the bytecode to verify it is proper:

# see how many codes we have nowwasmd query wasm list-code $NODE
# gas is huge due to wasm size... but auto-zipping reduced this from 1.8M to around 600k# you can see the code in the resultRES=$(wasmd tx wasm store artifacts/cw_nameservice.wasm --from wallet $TXFLAG -y)
# you can also get the code this wayCODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[0].value')
# no contracts yet, this should return an empty listwasmd query wasm list-contract-by-code $CODE_ID $NODE --output json
# you can also download the wasm from the chain and check that the diff between them is emptywasmd query wasm code $CODE_ID $NODE download.wasmdiff artifacts/cw_nameservice.wasm download.wasm

Instantiating the Contract#

We can now create an instance of this wasm contract. Here the verifier will fund an escrow, that will allow wallet to control payout and upon release, the funds go to bob.

# instantiate contract and verifyINIT='{"purchase_price":{"amount":"100","denom":"upebble"},"transfer_price":{"amount":"999","denom":"upebble"}}'wasmd tx wasm instantiate $CODE_ID "$INIT" \    --from wallet --label "awesome name service" $TXFLAG -y
# check the contract state (and account balance)wasmd query wasm list-contract-by-code $CODE_ID $NODE --output jsonCONTRACT=$(wasmd query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[-1]')echo $CONTRACT
wasmd query wasm contract $CONTRACT $NODE
# you can dump entire contract statewasmd query wasm contract-state all $CONTRACT $NODE
# Note that keys are hex encoded, and val is base64 encoded.# To view the returned data (assuming it is ascii), try something like:# (Note that in many cases the binary data returned is non in ascii format, thus the encoding)wasmd query wasm contract-state all $CONTRACT $NODE --output "json" | jq -r '.models[0].key' | xxd -r -pswasmd query wasm contract-state all $CONTRACT $NODE --output "json" | jq -r '.models[0].value' | base64 -d
# or try a "smart query", executing against the contractwasmd query wasm contract-state smart $CONTRACT '{}' $NODE# (since we didn't implement any valid QueryMsg, we just get a parse error back)

Once contract instantiated, let's register a name and transfer it with paying its price.

# execute fails if wrong personREGISTER='{"register":{"name":"fred"}}'wasmd tx wasm execute $CONTRACT "$REGISTER" \    --amount 100upebble \    --from wallet $TXFLAG -y
# query name recordNAME_QUERY='{"resolve_record": {"name": "fred"}}'wasmd query wasm contract-state smart $CONTRACT "$NAME_QUERY" $NODE --output json# {"data":{"address":"wasm1av9uhya7ltnusvunyqay3xcv9x0nyc872cheu5"}}
# buy and transfer name record to wallet2TRANSFER='{"transfer":{"name":"fred","to":"wasm1um2e88neq8sxzuuem5ztt9d0em033rpr5ps9tv"}}'wasmd tx wasm execute $CONTRACT "$TRANSFER" \    --amount 999upebble \    --from wallet $TXFLAG -y

Query record to see the new owner address:

NAME_QUERY='{"resolve_record": {"name": "fred"}}'wasmd query wasm contract-state smart $CONTRACT "$NAME_QUERY" $NODE --output json# {"data":{"address":"wasm1um2e88neq8sxzuuem5ztt9d0em033rpr5ps9tv"}}