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.

Ado_type: cw20

Version: 2.0.3-beta.1

InstantiateMsg

The symbol can only consist of letters and has to be between 3 and 12 characters.

Decimals will indicate how divisible your token is. Having a decimal of 6 means you could have 0.000001 of your token. Showcasing the decimalized amounts is usually handled by the front-end interface that would take the amount of tokens and divide it by the number of decimals. This means that when you transfer or send tokens from this ADO directly, you would still use whole numbers. For example, if I want to transfer 5 full tokens to someone and I have 6 decimals for my token, I would be sending 5000000 tokens from this ADO.

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 kernel_address: String,
    pub owner: Option<String>
    
}

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>,
}
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.

ExecuteMsg

Mint

Only with the "mint" extension. If authorized, creates amount new tokens and adds to the recipient balance.

 pub enum ExecuteMsg {
   Mint {
       recipient: String,
       amount: Uint128
        }
    }

Transfer

Transfer is a base message to move tokens to another account without triggering actions.

pub enum ExecuteMsg { 
  Transfer { 
     recipient: AndrAddr,
     amount: Uint128 
    }
  }

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.

pub enum ExecuteMsg {
     Send {
        contract: AndrAddr,
        amount: Uint128,
        msg: Binary,
    }
 }

Burn

Burn is a base message to destroy tokens forever

   pub enum ExecuteMsg {
      Burn {
        amount: Uint128,
    }
}

IncreaseAllowance

Sets an amount of tokens from the owner that the specified spender can interact with.

A new Expiration will overwrite a previous one.

 pub enum ExecuteMsg {
 IncreaseAllowance {
        spender: String,
        amount: Uint128,
        expires: Option<Expiration>,
    }
  }

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

  pub enum ExecuteMsg {
  DecreaseAllowance {
        spender: String,
        amount: Uint128,
        expires: Option<Expiration>,
    }
  }

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.

pub enum ExecuteMsg {
   TransferFrom {
        owner: String,
        recipient: String,
        amount: Uint128,
    }
  }

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.

 pub enum ExecuteMsg{
    SendFrom {
        owner: String,
        contract: String,
        amount: Uint128,
        msg: Binary,
     }
  }

BurnFrom

Burns a specified amount of tokens from the owner address forever.

The amount specified cannot exceed the allowance of the address executing BurnFrom.

pub enum ExecuteMsg{
 BurnFrom {
        owner: String,
        amount: Uint128,
    }
  }

UpdateMarketing

Updates the marketing information if instantiated.

Setting None/null for any of these will leave it unchanged

pub enum ExecuteMsg {
UpdateMarketing {
        project: Option<String>,
        description: Option<String>,
        marketing: Option<String>,
    }
 }

Uploads a Logo for the token.

pub enum ExecuteMsg {
    UploadLogo(Logo),
 }

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.

pub enum ExecuteMsg {   
     UpdateMinter {
           new_minter: Option<String> 
     },
}

Base Executes

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

QueryMsg

Balance

Queries the balance of a specific address.

pub enum QueryMsg {
   #[returns(cw20::BalanceResponse)]
   Balance {
    address:String,
     }
 }

BalanceResponse

 pub struct BalanceResponse {
    pub balance: Uint128,
}

TokenInfo

Returns metadata on the contract.

pub enum QueryMsg {
    #[returns(cw20::TokenInfoResponse)]
    TokenInfo {}
}

TokenInfoResponse

pub struct TokenInfoResponse {
    pub name: String,
    pub symbol: String,
    pub decimals: u8,
    pub total_supply: Uint128,
}

Minter

Returns who can mint and the hard cap on maximum tokens after minting

pub enum ExecuteMsg {
    #[returns(cw20::MinterResponse)]
    Minter {}
}

MinterResponse

pub struct MinterResponse {
    pub minter: String,
    pub cap: Option<Uint128>,

Allowance

Returns the amount of tokens that the spender has from the owner's tokens and the expiration for the tokens.

pub enum QueryMsg {
  #[returns(cw20::AllowanceResponse)]
  Allowance {
  owner: String,
  spender: String 
   }
 }

AllowanceResponse

pub struct AllowanceResponse {
    pub allowance: Uint128,
    pub expires: Expiration,
}

AllAllowanaces

Returns all the allowances that the specified owner has given along with the information for each allowance.

  pub enum QueryMsg{
    #[returns(cw20::AllAllowancesResponse)]
  AllAllowances {
        owner: String,
        start_after: Option<String>,
        limit: Option<u32>,
      }
   }

AllAllowanceResponse

pub struct AllAllowancesResponse {
    pub allowances: Vec<AllowanceInfo>,
}

AllowanceInfo

pub struct AllowanceInfo {
    pub spender: String,
    pub allowance: Uint128,
    pub expires: Expiration
}

AllSpenderAllowances

Returns all allowances this spender has been granted. Supports pagination.

pub enum QueryMsg {
  #[returns(cw20::AllSpenderAllowancesResponse)]
  AllSpenderAllowances {
        spender: String,
        start_after: Option<String>,
        limit: Option<u32>,
    },
  }

AllAccounts

Returns all the addresses that have a balance.

pub enum QueryMsg{
    #[returns(cw20::AllAccountsResponse)]
    AllAccounts {
        start_after: Option<String>,
        limit: Option<u32>,
    }
  }

AllAccountsResponse

pub struct AllAccountsResponse {
    pub accounts: Vec<String>,
}

MarketingInfo

Returns the metadata of the marketing of the project.

pub enum ExecuteMsg {
  #[returns(cw20::MarketingInfoResponse)]
  MarketingInfo {}
 }

MarketingInfoResponse

pub struct MarketingInfoResponse {
    pub project: Option<String>,
    pub description: Option<String>,
    pub logo: Option<LogoInfo>,
    pub marketing: Option<Addr>,
}

Downloads the embedded logo data (if stored on chain). Errors if no logo data stored for this contract.

pub enum ExecuteMsg {
    #[returns(cw20::DownloadLogoResponse)]
    DownloadLogo {}
  }

DownloadLogoResponse

pub struct DownloadLogoResponse {
    pub mime_type: String,
    pub data: Binary,
}

Base Queries

The rest of the query messages can be found in the ADO Base section.

Additional Resources

GithubWebsite