Query
How to Send a Query Request
- Command line
xplad query wasm contract-state smart <contract_address> '<JSON_formed_message>'
ex)
xplad query wasm contract-state smart xpla1kmag3937lrl6dtsv29mlfsedzngl9egv5c3apnr468q50gu04zrqea398u '{"pairs":{}}'
- RESTFul API
<light_clinet_address>/cosmwasm/wasm/v1/contract/<contract_address>/smart/<JSON_formed_message_with_base64>
ex) Where eyJwYWlycyI6e319
is Base64-encoded string of {"pairs":{}}
https://TODO/cosmwasm/wasm/v1/contract/xpla1.../smart/eyJwYWlycyI6e319
How to Organize a Query Message
You may check <contract>/src/msg.rs
of each contract.
Here is an example. Query messages are defined as below:
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
Balance { address: <Addr> },
...
}
This is one of the messages
Balance { address: <Addr> }
You may change it into snake case and add within {}
as like below:
{"balance": {"address": "<Addr>"}}
Addr
is a type, which is bech32-encoded address xpla
prefixed.
Here is an example:
{"balance": {"address": "xpla1..."}}
This rule also can be applied to other messages, so you can utilize this guide as a reference for your practice.