Terraport
Launch Terraport
  • Welcome to Terraport
  • Terraport FAQ
  • How To
    • Swap
    • Liquidity Providing
    • Staking
    • Liquid Staking
    • Farming
    • Leaderboard
      • Points
    • Launchpad
  • GOVERNANCE
    • Introduction
    • Proposal
    • Voting
  • SAFETY AND SECURITY
    • Audit
    • KYC
    • Bug Bounty
    • Safety and Risk Advice
      • Regulatory Advice
      • Terraport Advanced Products
      • Specific Risks of Cryptoassets
  • Developers
    • Mint Your CW20 Token
    • Create Your Own Pair
    • Query
  • Resources
    • Contracts
    • API
    • Roadmap
  • Sponsorship
    • Banner
  • Contact Us
    • Social Account & Communities
Powered by GitBook
On this page
  • How to Send a Query Request
  • How to Organize a Query Message

Was this helpful?

  1. Developers

Query

How to Send a Query Request

  • Command line

terrad query wasm contract-state smart <contract_address> '<JSON_formed_message>'

ex)

terrad query wasm contract-state smart terra1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqxl5qul '{"pairs":{}}'
  • RESTFul API

<light_clinet_address>/cosmwasm/wasm/v1/contract/<contract_address>/smart/<JSON_formed_message_with_base64>

ex)

https:://terra-classic-lcd.publicnode.com/cosmwasm/wasm/v1/contract/terra1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqxl5qul/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 terra prefixed. Here is an example:

{"balance": {"address": "terra1n75fgfc8clsssrm2k0fswgtzsvstdaah7la6sfu96szdu22xta0q57rqqr"}}

This rule also can be applied to other messages, so you can utilize this guide as a reference for your practice.

PreviousCreate Your Own PairNextContracts

Last updated 1 year ago

Was this helpful?