# CW20 Tokens

According to the official documentation (opens new window)

CW20 is a specification for fungible tokens based on CosmWasm. The name and design is loosely based on Ethereum's ERC20 standard, but many changes have been made. The types in here can be imported by contracts that wish to implement this spec, or by contracts that call to any standard cw20 contract.

# Checking CW20 balance

  • Query to /wasm/contracts/<tokenContractAddress>/store with query_msg {"balance":{"address":"<userAddress>"}}
  • Response: {"height":"2947306","result":{"balance":"24732816921"}}
  • Example (opens new window)

# Interacting with CW20 contract

  • CW20 is a cosmwasm contract and wasm/MsgExecuteContract is used to interact with it
  • Breakdown of message payload format is as follows (similar to bank/MsgSend but execute_msg is added):
{
  "type": "wasm/MsgExecuteContract",
  "value": {
    // sender address
    "sender": "terra1zyrpkll2xpgcdsz42xm3k8qfnddcdu0w7jzx6y",

    // token contract address
    "contract": "terra1rz5chzn0g07hp5jx63srpkhv8hd7x8pss20w2e",

    // base64-encoded payload of contract execution message (refer to below)
    "execute_msg": "ewogICJzZW5kIjogewogICAgImFtb3VudCI6ICIxMDAwMDAwMDAwIiwKICAgICJjb250cmFjdCI6IDxyZWNpcGllbnRDb250cmFjdEFkZHJlc3M+LAogICAgIm1zZyI6ICJleUp6YjIxbFgyMWxjM05oWjJVaU9udDlmUT09IiAKICB9Cn0=",

    // used in case you are sending native tokens along with this message
    "coins": []
  }
}

# Sending CW20 token to another contract, and execute message

// base64-encode the below message (without the comments), send that as `execute_msg`
{
  "send": {
    // amount of CW20 tokens being transferred
    "amount": "1000000000",

    // recipient of this transfer
    "contract": <recipientContractAddress>,

    // execute_msg to be executed in the context of recipient contract
    "msg": "eyJzb21lX21lc3NhZ2UiOnt9fQ==" 
  }
}

# Transferring CW20 token

{
  "transfer": {
    "amount": "1000000",
    "recipient": "<recipient>"
  }
}