Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.11 KB

INTERACTING_WASM.md

File metadata and controls

56 lines (38 loc) · 1.11 KB

If you want to query a contract you can (ensure the contract has the queries that match - we are using the cosmwasm-for-dummies example by Callum):

$BINARY q wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{}}'

which returns:

data:
count: 42

If we do:

$BINARY q wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{}}' --output json

we get:

{"data":{"count":42}}

Now let's change the state of the contract (increment):

$BINARY tx wasm execute $CONTRACT_ADDRESS '{"increment":{}}' --from test-user $TXFLAG

Now let's reset count to 0

$BINARY tx wasm execute $CONTRACT_ADDRESS '{"reset":{"count": 0}}' --from test-user $TXFLAG

You can also list contracts by id

$BINARY q wasm list-contract-by-code 5

Contract addresses are larger than user addresses (32 vs 20)

If you want the latest contract you can run:

CONTRACT_ADDRESS=$($BINARY q wasm list-contract-by-code $CONTRACT_CODE --output json | jq -r '.contracts[-1]')

Then you can do:

echo $CONTRACT_ADDRESS