This site requires Javascript to be enabled.

Interacting with your contract

Let's proceed to generating transactions and retrieving information from the contract we have deployed.

Querying

Queries read from the blockchain. They don't modify anything stored on chain, so they do not incur any gas fees.

There are several types of queries we can perform, but a common type that we are interested in is contract-state, which we will call in smart mode. This enables us to run queries with arguments, instead of dumping the entire contract data or metadata.

If we query the count before modifying any state, we get the value we set during instantiation:

archway contracts query smart CONTRACT [STDININPUT] [--json] [--log-level debug|error|info|warn] [--no-validation] [--args <value> | --args-file <value>| ]

A basic example for our increment contract would be:

archway contracts query smart increment --args '{"get_count": {}}'

Outputs:

{  "count": 0}

Why was the query argument {"get_count": {}}?

If we open src/contract.rs and inspect the function pub fn query, we will see the case matching statement that matches our JSON query:

pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {  match msg {      QueryMsg::GetCount {} => to_binary(&query_count(deps)?), // Here it is  }}

Info

QueryMsg is an enum with the GetCount property, defined in the src/msg.rs file. It is good to be aware of the format here, as the enum attribute is uppercase without spaces in Rust, but lowercase with snake case when converted to JSON arguments. This is controlled by the attribute #serde(rename_all = "snake_case") right above the QueryMsg definition.

Transacting

To increment our counter value, we'll be executing a transaction that calls the function pub fn try_increment in src/contract.rs. This function is already public, but the transaction execution is handled by the function pub fn execute in src/contract.rs, which does pattern matching to call try_increment.

Sending an Increment transaction, using the archway CLI:

archway contracts execute increment --args '{"increment": {}}'

Info

If you ever receive an out of gas error you can always use the --gas-adjustment flag and set a value of 1.5 or more.

Sending an Increment transaction, using archwayd:

mainnet

testnet

archwayd tx wasm execute --chain-id archway-1 archway188u72zstacfq4uknszr0cqry8vn68ynrcfcee4xjlmk6v2vhewysnkr798  '{"increment": {}}' --from my-wallet --node https://rpc.mainnet.archway.io:443 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3

Example output:

✔ Enter the name or address of the account that will send the transaction … mywalletExecuting contract increment2  Chain: constantine-3  Signer: mywallet✅ Executed contract  increment2-0.1.0  Transaction: CEFC1B9F6AE482249C3F6F3ED1C723F25FA8C129F53F5169544931207769311A

Why is the argument {"increment": {}}?

If we open src/contract.rs and inspect the pub fn execute function, we'll see a pattern matching statement that matches our JSON argument:

pub fn execute(  deps: DepsMut,  _env: Env,  info: MessageInfo,  msg: ExecuteMsg,) -> Result<Response, ContractError> {  match msg {    ExecuteMsg::Increment {} => try_increment(deps), // Here it is    ExecuteMsg::Reset { count } => try_reset(deps, info, count),  }}

As you can see, enum attributes again are converted. ExecuteMsg::Increment {} becomes {"increment": {}} in the CLI.

Info

While it doesn't apply to our Increment dapp, for dapps collecting payments, the MessageInfo struct is how developers can access and process incoming funds. Both native chain assets and cw20 tokens are supported by the funds attribute of MessageInfo.

pub struct MessageInfo {  pub sender: Addr,  pub funds: Vec<Coin>,}

When collecting payments in Archway's native token (e.g. ARCH for mainnet, CONST for Constantine testnet) amounts sent in funds should use the chain's minimum denomination (e.g. aarch for mainnet, aconst for Constantine testnet). Sending payment with other denominations (e.g. ARCH, or CONST) will fail with an error.

If our { "increment": {}} transaction succeeded and we query count again, it will have increased by 1*:

archway contracts query smart increment --args '{"get_count": {}}'

Now outputs:

{  "count": 1}

Drop Camp is here!

Join the queue and be one of the first to get in!.

Go Camping ↗