Andromeda
Ask or search…
⌃K
Comment on page

CW20

Introduction

The CW20 ADO is a smart contract to initiate a standard CW20 token. 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 contract supports modules to extend its functionality.
Ado_type: cw20

InstantiateMsg

The symbol can only consist of letters and has to be between 3 and 12 characters.
Rust
JSON
pub struct InstantiateMsg {
pub name: String,
pub symbol: String,
pub decimals: u8,
pub initial_balances: Vec<Cw20Coin>,
pub mint: Option<MinterResponse>,
pub marketing: Option<InstantiateMarketingInfo>,
pub modules: Option<Vec<Module>>,
pub kernel_address: String,
pub owner: Option<String>
}
{
"name": "mytoken",
"symbol":"MYT",
"decimals": 6,
"initial_balances":[
{
"address":"andr1...",
"amount":"500"
}
...
],
"mint":{
"minter":"andr1...",
"cap": "1000000"
},
"kernel_address":"andr1..."
​
}
Name
Type
Description
name
String
The name of the token.
symbol
String
The symbol of the token.
decimals
u8
The number of decimals for the token.
initial_balances
A vector containing a list of addresses and the amount of coin to initialize each.
mint
Optional field to define a minter for the token and an optional cap for the total supply of tokens that can be minted. If not defined, additional tokens cannot be minted.
marketing
Optional field to define the marketing information of the project.
modules
Option<Vec<Module>>
An optional vector of Andromeda Modules that can be attached to the contract. "address-list" module can be added.
kernel_address
String
Contract address of the kernel contract to be used for AMP messaging. Kernel contract address can be found in our deployed contracts.
owner
Option<String>
Optional address to specify as the owner of the ADO being created. Defaults to the sender if not specified.

Cw20Coin

Struct used to initiate balances for addresses. Contains an address and the amount of tokens for that address.
pub struct Cw20Coin {
pub address: String,
pub amount: Uint128,
}

InstantiateMarketingInfo

Struct used to store the marketing related data of the token.
pub struct InstantiateMarketingInfo {
pub project: Option<String>,
pub description: Option<String>,
pub marketing: Option<String>,
pub logo: Option<Logo>,
}
Name
Type
Text
project
Option<String>
A URL pointing to the project behind this token.
description
Option<String>
A longer description of the token and it's utility. Designed for tooltips or such.
marketing
Option<String>
The address (if any) who can update this data structure.
logo
Option<Logo>
A link to the logo, or a comment that there is an on-chain logo stored.
pub enum Logo {
Url(String),
Embedded(EmbeddedLogo),
}
  • Url: A reference to an externally hosted logo. Must be a valid HTTP or HTTPS URL.
  • Embedded: Logo content stored on the blockchain. Enforce maximum size of 5KB on all variants
pub enum EmbeddedLogo {
Svg(Binary),
Png(Binary),
}
  • Svg: Store the Logo as an SVG file. The content must conform to the specifications found here.
  • Png: Store the Logo as a PNG file. This will likely only support up to 64x64 or so within the 5KB limit.

MinterResponse

pub struct MinterResponse {
pub minter: String,
pub cap: Option<Uint128>,
}
The cap refers to the total supply. If it is not specified, then there is an unlimited cap.
Name
Type
Description
minter
String
The address to assign as a minter.
cap
Option<Uint128>
A hard cap on total amount of CW20 tokens that can be minted by this ADO.

ExecuteMsg

Mint

Only with the "mint" extension. If authorized, creates amount new tokens and adds to the recipient balance.
Rust
JSON
pub enum ExecuteMsg {
Mint {
recipient: String,
amount: Uint128
}
}
{
"mint":{
"recipient":"andr1...",
"amount": "100"
}
}
Name
Type
Description
recipient
String
The address to receive the minted tokens.
amount
Uint128
The amount of tokens to mint.

Transfer

Transfer is a base message to move tokens to another account without triggering actions.
Rust
JSON
pub enum ExecuteMsg {
Transfer {
recipient: String,
amount: Uint128
}
}
{
"transfer":{
"recipient":"andr1...",
"amount": "100"
}
}
Name
Type
Description
recipient
String
The address to transfer the tokens to.
amount
Uint128
The amount of tokens to transfer.

Send

Send is a base message to transfer tokens to a contract and trigger an action on the receiving contract.
The amount sent might be affected depending on the attached modules.
The msg should be base64 encoded and not raw binary.
This message is used when sending tokens to other ADOs that interact with CW20 tokens. In that case, the msg should be a CW20HookMsg that would be defined in the ADOs documentation page.
Rust
JSON
pub enum ExecuteMsg {
Send {
contract: String,
amount: Uint128,
msg: Binary,
}
}
{
"send":{
"contract":"andr1...",
"amount":"100",
"msg":"eyJzZW5kIjp7fX0="
}
}
Name
Type
Description
contract
String
The address of the receiving contract.
amount
Uint128
The amount to send.
msg
Binary
A message to be sent to the receiving contract.

Burn

Burn is a base message to destroy tokens forever
Rust
JSON
pub enum ExecuteMsg {
Burn {
amount: Uint128,
}
}
{
"burn": {
"amount": "100"
}
}
Name
Type
Description
amount
Uint128
The amount of coins to be burnt.

IncreaseAllowance

Sets an amount of tokens from the owner that the specified spender can interact with.
A new Expiration will overwrite a previous one.
Rust
JSON
pub enum ExecuteMsg {
IncreaseAllowance {
spender: String,
amount: Uint128,
expires: Option<Expiration>,
}
}
{
"increase_allowance":{
"spender":"andr1...",
"amount":"1000"
}
}
Name
Type
Description
spender
String
The address to receive the allowance.
amount
Uint128
The amount of tokens to give the spender access to.
expires
Option<Expiration>
Optional Expiration for the allowance of the spender.

DecreaseAllowance

Decreases the allowance set for the spender by the set amount.
The amount specified in DecreaseAllowance does not replace the old amount but is subtracted from it. If the result is 0 or less, then the spender no longer has an Allowance from the owner.
If an Expiration is set, it will overwrite previously set Expiration
Rust
JSON
pub enum ExecuteMsg {
DecreaseAllowance {
spender: String,
amount: Uint128,
expires: Option<Expiration>,
}
}
{
"decrease_allowance": {
"spender":"andr1...",
"amount":"100",
"expires": {
"at_height": "500"
}
}
}
Name
Type
Description
spender
String
The address to have their allowance decreased.
amount
Uint128
The amount to decrease the allowance by.
expires
Option<Expiration>
Optional expiration for the allowance of the spender.

TransferFrom

Transfers the amount of tokens from the owner address to the recipient.
The amount specified cannot exceed the allowance of the address executing TransferFrom.
Rust
JSON
pub enum ExecuteMsg {
TransferFrom {
owner: String,
recipient: String,
amount: Uint128,
}
}
{
"transfer_from":{
"owner":"andr1...",
"recipient":"andr1...",
"amount":"50"
}
}
Name
Type
Description
owner
String
The owner address that has the tokens to transfer.
recipient
String
The address the receive the tokens.
amount
Uint128
The amount of tokens to send from the owner to the recipient.

SendFrom

Sends the amount of tokens from the owner address to the contract address. Can use a msg to trigger an action on the receiving contract.
The amount specified cannot exceed the allowance of the address executing TransferFrom.
The msg should be base64 encoded and not raw binary.
Rust
JSON
pub enum ExecuteMsg{
SendFrom {
owner: String,
contract: String,
amount: Uint128,
msg: Binary,
}
}
{
"send_from":{
"owner":"andr1...",
"contract":"andr1...",
"amount":"100",
"msg": "eyJzZW5kIjp7fX0="
}
}
Name
Type
Description
owner
String
The owner address that has the tokens to transfer.
contract
String
The contract address to receive the tokens.
amount
Uint128
The amount of tokens to send from the owner to the contract.
msg
Binary
A message to be sent to the receiving contract.

BurnFrom

Burns a specified amount of tokens from the owner address forever.
The amount specified cannot exceed the allowance of the address executing BurnFrom.
Rust
JSON
pub enum ExecuteMsg{
BurnFrom {
owner: String,
amount: Uint128,
}
}
{
"burn_from":{
"owner":"andr1...",
"amount": "100"
}
}
Name
Type
Description
owner
String
The address to burn tokens from.
amount
Uint128
The amount of tokens to burn.

UpdateMarketing

Updates the marketing information if instantiated.
Setting None/null for any of these will leave it unchanged
Rust
JSON
pub enum ExecuteMsg {
UpdateMarketing {
project: Option<String>,
description: Option<String>,
marketing: Option<String>,
}
}
{
"update_marketing":{
"project":"http...",
"marketing":"andr1..."
}
}
Name
Type
Description
project
Option<String>
A URL pointing to the project behind this token.
description
Option<String>
A longer description of the token and it's utility. Designed for tooltips or such.
marketing
Option<String>
The address (if any) who can update this data structure.
Uploads a Logo for the token.
Rust
JSON
pub enum ExecuteMsg {
UploadLogo(Logo),
}
{
"upload_logo":{
"url":"https://www..."
}
}
Check Logo.

UpdateMinter

Only with the "mintable" extension. The current minter may set a new minter. Setting the minter to None will remove the token's minter forever.
Only available to the current minter.
Rust
JSON
pub enum ExecuteMsg {
UpdateMinter {
new_minter: Option<String>
},
}
{
"update_minter":{
"new_minter":"andr1..."
}
}
Name
Type
Description
new_minter
Option<String>
The address of the new minter. If not specified, then the token minter is removed forever.

Base Executes

Uses the modules feature.
The rest of the execute messages can be found in the ADO Base section.

QueryMsg

Balance

Queries the balance of a specific address.
Rust
JSON
pub enum QueryMsg {
#[returns(cw20::BalanceResponse)]
Balance {
address:String,
}
}
{
"balance":{
"address":"andr1..."
}
}
Name
Type
Description
address
String
The address to get the balance of.

BalanceResponse

Rust
JSON
pub struct BalanceResponse {
pub balance: Uint128,
}
{
"balance":"100"
}
Name
Type
Description
balance
Uint128
The amount of tokens the specified address has in their balance.

TokenInfo

Returns metadata on the contract.
Rust
JSON
pub enum QueryMsg {
#[returns(cw20::TokenInfoResponse)]
TokenInfo {}
}
{
"token_info":{}
}

TokenInfoResponse

Rust
JSON
pub struct TokenInfoResponse {
pub name: String,
pub symbol: String,
pub decimals: u8,
pub total_supply: Uint128,
}
{
"name":"mytoken",
"symbol":"MYT",
"decimals": 6,
"total_supply":"10000000"
}
Name
Type
Description
name
String
The name of the token.
symbol
String
The symbol of the token.
decimals
u8
The number of decimals for the token.
total_supply
Uint128
The total amount of tokens.

Minter

Returns who can mint and the hard cap on maximum tokens after minting
Rust
JSON
pub enum ExecuteMsg {
#[returns(cw20::MinterResponse)]
Minter {}
}
{
"minter":{}
}

MinterResponse

Rust
JSON
pub struct MinterResponse {
pub minter: String,
pub cap: Option<Uint128>,
{
"minter":"andr1...",
"cap":"1000000"
}
Name
Type
Description
minter
String
The address of the assigned minter.
cap
Option<Uint128>
Cap is a hard cap on total supply that can be achieved by minting.

Allowance

Returns the amount of tokens that the spender has from the owner's tokens and the expiration for the tokens.
Rust
JSON
pub enum QueryMsg {
#[returns(cw20::AllowanceResponse)]
Allowance {
owner: String,
spender: String
}
}
{
"allowance": {
"owner":"andr1...",
"spender":"andr1..."
}
}
Name
Type
Description
owner
String
The address of the owner of the tokens.
spender
String
The address to check the allowance of.

AllowanceResponse

Rust
JSON
pub struct AllowanceResponse {
pub allowance: Uint128,
pub expires: Expiration,
}
{
"allowance":"1000",
"expires":{
"at_height":"500"
}
}
Name
Type
Description
allo