LogoLogo
WebDiscordTelegramBlog
  • Source Protocol
    • Introduction
    • Vision
    • Business Solutions
    • DeFi-as-a-Service
    • Ecosystem Overview
    • JOIN SOURCE
  • SOURCE - $SOURCE
    • Tokenomics
    • Features Part 1
    • Features Part 2
    • Why Guardian Nodes?
    • Source Swap
    • Airdrop
    • Claim Source-Drop
    • How to IBC Transfer
    • Community
  • SourceSwap - On Chain DEX
    • Connect and Deposit
    • Swap
    • Manage Liquidity
  • Governance
    • Before Submitting a Proposal
    • Submitting a Proposal (CLI)
  • COMMAND-LINE INTERFACE (CLI)
    • Introduction
    • Useful CLI Commands
  • SMART CONTRACTS & SOURCED DEVELOPMENT
    • Sourced Local Dev Setup
    • Source Chain Testnet Setup
      • Testnet Links
    • Smart Contracts with COSMWASM
    • CW-20/ERC-20 Tutorial
      • Installation
      • Download, Compile, Store
      • Initialize the Contract
      • Query and run commands
    • CW1 Tutorial
      • Installation
      • Download, Compile, Store
      • Initialize the Contract
      • Query commands
      • Execute commands
  • Nodes & Validators
    • Mainnet: Sourced Installation and Setup
    • Setting up Cosmovisor
    • Mainnet Setup and Tooling
    • Joining Mainnet
    • Mainnet Upgrades
    • Mainnet Resources
    • Block, Height & State-Sync Source with KSYNC
  • PLANQ | SOURCE Bridge
    • Bridging SRCX from BNB Chain to SOURCE Chain
  • SOURCE MARKET DOCUMENTATION
    • Source Market
    • Introduction
    • sTokens
    • Unitroller
    • USX Controller
    • Governance
  • BRANDING & RESOURCES
    • Social, Resources & Updates
    • Branding
    • Videos
    • How to: MetaMask
    • How to: Keplr
  • Gaming
    • Moochkin's Metarun
      • Rewards and Tournaments
  • LEGAL
    • Disclaimer
    • Privacy Policy
Powered by GitBook
On this page
  1. SMART CONTRACTS & SOURCED DEVELOPMENT
  2. CW-20/ERC-20 Tutorial

Query and run commands

Query and execute commands on your new contract

Now you can check that the contract has assigned the right amount to the self-delegate address:

sourced query wasm contract-state smart <contract-address> '{"balance":{"address":"<validator-self-delegate-address>"}}' -b block 

From the example above, it will return:

data:
  balance: "12345678000"

Using the commands supported by execute work the same way. The incantation for executing commands on a contract via the CLI is:

sourced tx wasm execute [contract_addr_bech32] [json_encoded_send_args] --amount [coins,optional] [flags]

You can omit --amount if not needed for execute calls.

You will likely need to add additional flags depending on your local node's gas settings. If in doubt, --gas-prices 0.1usource --gas auto --gas-adjustment 1.3 will work. If you also add -b block, then the tx will block until complete or failed, rather than executing asynchronously.

In this case, your command will look something like:

sourced tx wasm execute <contract-addr> '{"transfer":{"amount":"200","owner":"<validator-self-delegate-address>","recipient":"<recipient-address>"}}' --from <your-key> --chain-id <chain-id>

Passing arguments

As before, you can encode whatever JSON arguments you need via the node CLI (or another tool of your choice). But how do you know what arguments to use?

Every contract specifies the arguments that can be used for each action exposed to execute. Their types are also specified.

This specification, or spec, for short, can be found in the schema for the contract.

In the folder contracts/erc20 within cosmwasm-examples, for example, you can see the schemas:

tree schema

schema
├── allowance_response.json
├── balance_response.json
├── constants.json
├── execute_msg.json
├── instantiate_msg.json
└── query_msg.json

Each of the JSON files above is a JSON schema, specifying the correct shape of JSON that it accepts.

Even though it is your job as a developer to provide documentation to your users, at a bare minimum, the schema will enforce argument correctness and provide basic documentation to others.

PreviousInitialize the ContractNextCW1 Tutorial

Last updated 2 years ago