var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=3&rec=1&url=https://docs.warp.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Queries

This section details queries and their structure. For general information on writing conditions, visit the Conditions and expressions page. To view an example of a query variable in a template, visit the template guide.

Queries are written as variables that select a value from a query message. The structure of a QueryVariable contains a selector, a query request, and a name. Any type of query supported by Cosmos can be used in a condition. For more information on query variables and update functions, visit the Variables page.

Query variables can be used as one or both of the values in a general expression, or in boolean expressions. When query expressions are used in a condition, the JSON of a query message is sent out, and the value specified by the selector string is returned as the value to be compared in the general expression.

condition.rs

_10
pub struct QueryExpr {
_10
pub selector: String,
_10
pub query: QueryRequest<String>,
_10
}

QueryRequest

Warp conditions support any query type available using the QueryRequest struct, which outlines all possible query calls. The possible query types are Bank, Custom, Staking, Stargate, IBC, and Wasm.

mod.rs

_21
pub enum QueryRequest<C> {
_21
Bank(BankQuery),
_21
Custom(C),
_21
#[cfg(feature = "staking")]
_21
Staking(StakingQuery),
_21
/// A Stargate query is encoded the same way as abci_query, with path and protobuf encoded request data.
_21
/// The format is defined in [ADR-21](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-021-protobuf-query-encoding.md).
_21
/// The response is protobuf encoded data directly without a JSON response wrapper.
_21
/// The caller is responsible for compiling the proper protobuf definitions for both requests and responses.
_21
#[cfg(feature = "stargate")]
_21
Stargate {
_21
/// this is the fully qualified service path used for routing,
_21
/// eg. custom/cosmos_sdk.x.bank.v1.Query/QueryBalance
_21
path: String,
_21
/// this is the expected protobuf message type (not any), binary encoded
_21
data: Binary,
_21
},
_21
#[cfg(feature = "stargate")]
_21
Ibc(IbcQuery),
_21
Wasm(WasmQuery),
_21
}

Bank Queries

Bank queries are used to query information from the Cosmos bank module.

bank.rs

_14
pub enum BankQuery {
_14
/// This calls into the native bank module for querying the total supply of one denomination.
_14
/// It does the same as the SupplyOf call in Cosmos SDK's RPC API.
_14
/// Return value is of type SupplyResponse.
_14
#[cfg(feature = "cosmwasm_1_1")]
_14
Supply { denom: String },
_14
/// This calls into the native bank module for one denomination
_14
/// Return value is BalanceResponse
_14
Balance { address: String, denom: String },
_14
/// This calls into the native bank module for all denominations.
_14
/// Note that this may be much more expensive than Balance and should be avoided if possible.
_14
/// Return value is AllBalanceResponse.
_14
AllBalances { address: String },
_14
}

Supply

Returns the total supply of a denomination.

JSON

_10
{
_10
"bank": {
_10
"supply": {
_10
"demom": "<String>"
_10
}
_10
}
_10
}

Response

_10
{
_10
"supply": [
_10
{
_10
"denom": "uluna",
_10
"amount": "266507"
_10
}
_10
]
_10
}

Balance

Queries the amount of a specific denomination for a given address.

JSON

_10
{
_10
"bank": {
_10
"balance": {
_10
"address": "<String>",
_10
"denom": "<String>"
_10
}
_10
}
_10
}

Response

_10
{
_10
"amount": [
_10
{
_10
"denom": "uluna",
_10
"amount": "266507"
_10
}
_10
]
_10
}

AllBalances

This query calls into the native bank module for all denominations. Note that this may be much more expensive than Balance and should be avoided if possible. The return value is AllBalanceResponse.

JSON

_10
{
_10
"bank": {
_10
"all_balances": {
_10
"address": "<String>"
_10
}
_10
}
_10
}

Response

_10
{
_10
"all_balances": [
_10
{
_10
"denom": "uluna",
_10
"amount": "266507"
_10
}
_10
]
_10
}

Staking Queries

Staking queries are used to query information from the Cosmos staking module.

bank.rs

_24
pub enum StakingQuery {
_24
/// Returns the denomination that can be bonded (if there are multiple native tokens on the chain)
_24
BondedDenom {},
_24
/// AllDelegations will return all delegations by the delegator
_24
AllDelegations { delegator: String },
_24
/// Delegation will return more detailed info on a particular
_24
/// delegation, defined by delegator/validator pair
_24
Delegation {
_24
delegator: String,
_24
validator: String,
_24
},
_24
/// Returns all validators in the currently active validator set.
_24
///
_24
/// The query response type is `AllValidatorsResponse`.
_24
AllValidators {},
_24
/// Returns the validator at the given address. Returns None if the validator is
_24
/// not part of the currently active validator set.
_24
///
_24
/// The query response type is `ValidatorResponse`.
_24
Validator {
_24
/// The validator's address (e.g. (e.g. cosmosvaloper1...))
_24
address: String,
_24
},
_24
}

BondedDenom

Returns all bonded denominations. Terra only uses uluna.

JSON

_10
{
_10
"staking": {
_10
"bonded_denom": {}
_10
}
_10
}

Response

_10
{
_10
"denom": "uluna"
_10
}

AllDelegations

Returns all delegations of a delegator.

JSON

_10
{
_10
"staking": {
_10
"all_delegations": {
_10
"delegator": "<terra_address>"
_10
}
_10
}
_10
}

Response

_13
_13
{
_13
"delegations": [
_13
{
_13
"delegator": "<terra_address>",
_13
"validator": "<terravaloper_address>",
_13
"amount": {
_13
"denom": "uluna",
_13
"amount": "190886529"
_13
}
_13
}
_13
]
_13
}

Delegation

Returns detailed delegation information.

JSON

_10
{
_10
"staking": {
_10
"delegation": {
_10
"delegator": "<terra_address>",
_10
"validator": "<terravaloper_address>"
_10
}
_10
}
_10
}

Response

_20
{
_20
"delegation": {
_20
"delegator": "<terra_address>",
_20
"validator": "<terravaloper_address>",
_20
"amount": {
_20
"denom": "uluna",
_20
"amount": "190886529"
_20
},
_20
"accumulated_rewards": [
_20
{
_20
"denom": "uluna",
_20
"amount": "14323941"
_20
}
_20
],
_20
"can_redelegate": {
_20
"denom": "uluna",
_20
"amount": "190886529"
_20
}
_20
}
_20
}

AllValidators

Returns the entire active validator set.

JSON

_10
{
_10
"staking": {
_10
"all_validators": {}
_10
}
_10
}

Response

_19
{
_19
"validators": [
_19
{
_19
"address": "<terravaloper_address>",
_19
"commission": "0.000000000000000000",
_19
"max_commission": "0.200000000000000000",
_19
"max_change_rate": "0.010000000000000000"
_19
},
_19
{
_19
"address": "<terravaloper_address>",
_19
"commission": "0.050000000000000000",
_19
"max_commission": "0.100000000000000000",
_19
"max_change_rate": "0.010000000000000000"
_19
},
_19
_19
...
_19
_19
]
_19
}

Validator

Returns the validator at the given address.

JSON

_10
{
_10
"staking": {
_10
"validator": {
_10
"address": "<String>"
_10
}
_10
}
_10
}

Response

_10
{
_10
"validator": {
_10
"address": "<terravaloper_address>",
_10
"commission": "0.050000000000000000",
_10
"max_commission": "0.200000000000000000",
_10
"max_change_rate": "0.200000000000000000"
_10
}
_10
}

Wasm Queries

Wasm queries are used to query information from the Cosmos Wasm module. For WASM queries, you must know the format of your Response.

wasm.rs

_19
pub enum WasmQuery {
_19
/// this queries the public API of another contract at a known address (with known ABI)
_19
/// Return value is whatever the contract returns (caller should know), wrapped in a
_19
/// ContractResult that is JSON encoded.
_19
Smart {
_19
contract_addr: String,
_19
/// msg is the json-encoded QueryMsg struct
_19
msg: Binary,
_19
},
_19
/// this queries the raw kv-store of the contract.
_19
/// returns the raw, unparsed data stored at that key, which may be an empty vector if not present
_19
Raw {
_19
contract_addr: String,
_19
/// Key is the raw key used in the contracts Storage
_19
key: Binary,
_19
},
_19
/// returns a ContractInfoResponse with metadata on the contract from the runtime
_19
ContractInfo { contract_addr: String },
_19
}

Smart

Queries the public API of another contract at a known address (with known ABI). The return value is wrapped in a ContractResult that is JSON encoded. The msg is the json-encoded QueryMsg struct.

JSON

_10
{
_10
"wasm": {
_10
"smart": {
_10
"contract_addr": "<String>",
_10
"msg": "<Binary>"
_10
}
_10
}
_10
}

Raw

Queries the raw kv-store of the contract. Returns the raw, unparsed data stored at that key, which may be an empty vector if not present.

JSON

_10
{
_10
"wasm": {
_10
"raw": {
_10
"contract_addr": "<String>",
_10
"key": "<Binary>"
_10
}
_10
}
_10
}

ContractInfo

Returns a ContractInfoResponse with metadata on the contract from the runtime

JSON

_10
{
_10
"wasm": {
_10
"raw": {
_10
"contract_info": {
_10
"contract_addr": "<String>"
_10
}
_10
}
_10
}
_10
}

wasm.rs

_25
pub struct ContractInfoResponse {
_25
pub code_id: u64,
_25
/// address that instantiated this contract
_25
pub creator: String,
_25
/// admin who can run migrations (if any)
_25
pub admin: Option<String>,
_25
/// if set, the contract is pinned to the cache, and thus uses less gas when called
_25
pub pinned: bool,
_25
/// set if this contract has bound an IBC port
_25
pub ibc_port: Option<String>,
_25
}
_25
_25
impl ContractInfoResponse {
_25
/// Convenience constructor for tests / mocks
_25
#[doc(hidden)]
_25
pub fn new(code_id: u64, creator: impl Into<String>) -> Self {
_25
Self {
_25
code_id,
_25
creator: creator.into(),
_25
admin: None,
_25
pinned: false,
_25
ibc_port: None,
_25
}
_25
}
_25
}

Selectors

Selector strings are used in query expressions to select the JSON path of the query response. You can think of a selector string as the path that Warp needs to take within that particular query response to get the value that needs comparing.

Example:

To select "bend" as the desired portion of the query response below, the $.address.city selector is used. The $ in the selector refers to the root object/element.

example.json

_10
{
_10
"address": {
_10
"streetAddress": "high street",
_10
"city": "bend",
_10
"postalCode": "97701"
_10
}
_10
}

For a hands-on example of JSON paths and selectors, visit the JSON path evaluator. To learn more about JSON selectors, visit the JSON path Github repo.