This site requires Javascript to be enabled.

Execute transactions

After instantiating your CW20 token, you can interact with it through various transactions. These transactions allow you to perform operations such as transferring tokens, mint and burn tokens, approving spending allowances, and more. Each transaction is executed by sending a specific command to your contract.

Let's start with one of the most common operations: transferring tokens. This will serve as a foundation for understanding how to execute other types of transactions within your CW20 token contract.

Transfer tokens

To transfer tokens from one account to another, use the transfer command. Here's the syntax using the Archway Developer CLI:

archway contracts execute <contract-name> --args '{
  "transfer": {
    "recipient": "<recipient_address>",
    "amount": "<amount>"
  }
}'

Replace <contract-name> with your contract's name, <recipient_address> with the recipient's address, and <amount> with the number of tokens to transfer.

Example:

archway contracts execute my-cw20-token --args '{
  "transfer": {
    "recipient": "archway1...",
    "amount": "1000000"
  }
}'

Upon successful execution, you should see output similar to:

Executing contract cw20test2
Chain: constantine-3
Signer: mywallet

✅ Executed contract  cw20test2-0.1.0
Transaction: https://testnet.archway.explorers.guru/transaction/EA47A832ABDD978174DAFB965253147668C65DA377FB848A6E7B7D58F758ED54

Note: Ensure you have sufficient tokens and gas fees in your account to execute transactions.

Understanding the transfer command

The transfer command is structured as follows:

{  "transfer": {    "recipient": "archway1recipientaddress...",    "amount": "100"  }}

This JSON structure corresponds to the contract's internal logic for handling transfers. Let's break down how this works:

  1. Contract Structure: In the src/contract.rs file, you'll find the main execute function:
pub fn execute(  deps: DepsMut,  env: Env,  info: MessageInfo,  msg: ExecuteMsg,) -> Result<Response, ContractError> {  match msg {    ExecuteMsg::Transfer { recipient, amount } => {      execute_transfer(deps, env, info, recipient, amount)    },    // other cases...  }}
  1. Message Types: The ExecuteMsg enum in src/msg.rs defines all possible actions that can modify the contract's state, including transfers.
  2. JSON Formatting: The #[serde(rename_all = "snake_case")] attribute ensures that JSON keys are formatted in snake_case, matching the contract's expectations.

By understanding this structure, you can effectively interact with your CW20 token contract, not just for transfers but for all supported operations.

Send tokens

The send operation is similar to transfer, but with an important distinction: it not only moves tokens to another account but also triggers a contract execution on the recipient's side. This enables more complex interactions, such as depositing tokens into a staking contract or interacting with decentralized exchanges.

To execute a send operation, use the following command structure:

archway contracts execute <contract-name> --args '{
  "send": {
    "contract": "<contract_address>",
    "amount": "<amount>",
    "msg": "<base64_encoded_message>"
  }
}'

Replace:

  • <contract-name> with your token contract's name
  • <contract_address> with the address of the receiving contract
  • <amount> with the number of tokens to send
  • <base64_encoded_message> with a Base64-encoded message for the receiving contract

Example:

archway contracts execute my-cw20-token --args '{
  "send": {
    "contract": "archway1...",
    "amount": "1000000",
    "msg": "eyJkZXBvc2l0Ijp7fX0="
  }
}'

Important notes:

  • The msg parameter is a Base64-encoded JSON string that specifies the action for the receiving contract to perform.
  • The receiving contract must implement the CW20 receive interface to handle incoming tokens.
  • This operation allows for seamless integration with other smart contracts in the ecosystem.
  • Be sure you trust the receiving contract and understand its behavior before sending tokens.

Burn tokens

The burn operation allows you to permanently remove a specified amount of tokens from your balance, effectively reducing the total supply of the token. This can be useful for various tokenomic strategies or to implement deflationary mechanisms.

To burn tokens, use the following command structure:

archway contracts execute <contract-name> --args '{
  "burn": {
    "amount": "<amount>"
  }
}'

Replace <contract-name> with your contract's name and <amount> with the number of tokens you wish to burn.

Example:

archway contracts execute my-cw20-token --args '{
  "burn": {
    "amount": "1000000"
  }
}'

Note:

  • You can only burn tokens from your own balance.
  • The burn operation is irreversible, so use it with caution.

This operation will permanently remove the specified amount of tokens from circulation, reducing the total supply of your CW20 token.

The following is an example of the output:

Executing contract cw20test2
Chain: constantine-3
Signer: mywallet

✅ Executed contract  cw20test2-0.1.0
Transaction: https://testnet.archway.explorers.guru/transaction/716951B06A735AEEFBE8C06854A4D0BB649770E209A4D5B99E6AFDAD941D87E6

Mint tokens

The mint operation allows you to create new tokens and add them to a specified account's balance, thereby increasing the total supply of your CW20 token. This function is typically restricted to authorized accounts (minters) as defined during contract instantiation.

To mint new tokens, use the following command structure:

archway contracts execute <contract-name> --args '{
  "mint": {
    "recipient": "<recipient_address>",
    "amount": "<amount>"
  }
}'

Replace <contract-name> with your contract's name, <recipient_address> with the address to receive the new tokens, and <amount> with the number of tokens to mint.

Example:

archway contracts execute my-cw20-token --args '{
  "mint": {
    "recipient": "archway1...",
    "amount": "1000000"
  }
}'

Important notes:

  • Only authorized minter addresses can execute this command.
  • If a cap was set during instantiation, minting cannot exceed this limit.

Increase allowance

The increase allowance operation enables a token holder to grant or increase permission for another account to spend a specified amount of tokens on their behalf. This is useful for various scenarios, such as decentralized exchanges or automated token management systems.

To increase an allowance, use the following command structure:

archway contracts execute <contract-name> --args '{
  "increase_allowance": {
    "spender": "<spender_address>",
    "amount": "<amount>",
    "expires": <optional_expiration>
  }
}'

Replace:

  • <contract-name> with your contract's name
  • <spender_address> with the address being granted the allowance
  • <amount> with the additional amount of tokens to allow
  • <optional_expiration> with an expiration time for the allowance (optional)

Example:

archway contracts execute my-cw20-token --args '{
  "increase_allowance": {
    "spender": "archway1...",
    "amount": "1000000"
  }
}'

Important notes:

  • This operation increases the existing allowance. If no allowance existed, it creates a new one.
  • The allowance represents the maximum amount the spender can transfer on your behalf.
  • You can add an optional expiration to the allowance for added security.
  • Be cautious when setting allowances, as they grant spending rights to other accounts.

The following is an example of the output:

Executing contract cw20test2
Chain: constantine-3
Signer: mywallet

✅ Executed contract  cw20test2-0.1.0
Transaction: https://testnet.archway.explorers.guru/transaction/52F460D32DCCF194190CE55C41EB912612B9F52A01F52CA919D9FB11724692C7

Decrease allowance

The decrease allowance operation enables a token holder to reduce the amount that an approved spender can spend on their behalf. This provides fine-grained control over spending permissions and can be used to adjust or revoke previously granted allowances.

To decrease an allowance, use the following command structure:

archway contracts execute <contract-name> --args '{
  "decrease_allowance": {
    "spender": "<spender_address>",
    "amount": "<amount>",
    "expires": <optional_expiration>
  }
}'

Replace:

  • <contract-name> with your contract's name
  • <spender_address> with the address of the spender whose allowance you're decreasing
  • <amount> with the amount by which to decrease the allowance
  • <optional_expiration> with an updated expiration time for the allowance (optional)

Example:

archway contracts execute my-cw20-token --args '{
  "decrease_allowance": {
    "spender": "archway1...",
    "amount": "500000"
  }
}'

Important notes:

  • This operation reduces the existing allowance. If the decrease amount exceeds the current allowance, it will set the allowance to zero.
  • You cannot decrease an allowance below zero.
  • If you want to completely revoke an allowance, you can decrease it by an amount equal to or greater than the current allowance.
  • Like with increase_allowance, you can optionally update the expiration of the allowance.

The following is an example of the output:

Executing contract cw20test2
Chain: constantine-3
Signer: mywallet

✅ Executed contract  cw20test2-0.1.0
Transaction: https://testnet.archway.explorers.guru/transaction/7FB0B6B3964F4ADA3984A2A8F0FCEFE312559E85DF39806120E8BFA35709C49F

Transfer from

The transfer from operation allows a third party to transfer tokens between two accounts, provided they have been granted sufficient allowance by the token owner. This feature is crucial for scenarios where tokens need to be managed by someone other than their owner, such as in decentralized exchanges or automated portfolio management systems.

To execute a transfer from operation, use the following command structure:

archway contracts execute <contract-name> --args '{
  "transfer_from": {
    "owner": "<sender_address>",
    "recipient": "<recipient_address>",
    "amount": "<amount>"
  }
}'

Replace:

  • <contract-name> with your contract's name
  • <sender_address> with the address of the token owner
  • <recipient_address> with the address receiving the tokens
  • <amount> with the number of tokens to transfer

Example:

archway contracts execute my-cw20-token --args '{
  "transfer_from": {
    "owner": "archway1sender...",
    "recipient": "archway1recipient...",
    "amount": "1000000"
  }
}'

Important notes:

  • The account executing this command must have a sufficient allowance from the owner to cover the transfer amount.
  • This operation deducts from both the owner's balance and the spender's allowance.
  • If the transfer amount exceeds the available allowance, the transaction will fail.
  • This feature enables complex token management scenarios without requiring direct interaction from the token owner.

Burn from

The burn from operation allows a third party to burn (permanently remove) tokens from another account's balance, provided they have been granted sufficient allowance by the token owner. This operation reduces the total supply of the token and can be useful in various tokenomic strategies or when implementing controlled deflation mechanisms.

To execute a burn from operation, use the following command structure:

archway contracts execute <contract-name> --args '{
  "burn_from": {
    "owner": "<owner_address>",
    "amount": "<amount>"
  }
}'

Replace:

  • <contract-name> with your contract's name
  • <owner_address> with the address of the token owner
  • <amount> with the number of tokens to burn

Example:

archway contracts execute my-cw20-token --args '{
  "burn_from": {
    "owner": "archway1owner...",
    "amount": "1000000"
  }
}'

Important notes:

  • The account executing this command must have a sufficient allowance from the owner to cover the burn amount.
  • This operation deducts from both the owner's balance and the spender's allowance.
  • The burned tokens are permanently removed from circulation, reducing the total token supply.
  • If the burn amount exceeds the available allowance or the owner's balance, the transaction will fail.
  • This feature can be used in various scenarios, such as implementing token buyback and burn mechanisms.

Send from

The send from operation combines the functionality of transfer from and send. It allows a third party to send tokens from the owner's account to a recipient contract, triggering an execution on the recipient contract. This operation is useful for complex interactions where an approved entity needs to manage tokens and interact with other contracts on behalf of the token owner.

To execute a send from operation, use the following command structure:

archway contracts execute <contract-name> --args '{
  "send_from": {
    "owner": "<owner_address>",
    "contract": "<recipient_contract_address>",
    "amount": "<amount>",
    "msg": "<base64_encoded_message>"
  }
}'

Replace:

  • <contract-name> with your token contract's name
  • <owner_address> with the address of the token owner
  • <recipient_contract_address> with the address of the contract receiving the tokens
  • <amount> with the number of tokens to send
  • <base64_encoded_message> with a Base64-encoded message for the receiving contract

Example:

archway contracts execute my-cw20-token --args '{
  "send_from": {
    "owner": "archway1owner...",
    "contract": "archway1recipient...",
    "amount": "1000000",
    "msg": "eyJkZXBvc2l0Ijp7fX0="
  }
}'

Important notes:

  • The account executing this command must have a sufficient allowance from the owner.
  • This operation deducts from both the owner's balance and the spender's allowance.
  • The msg parameter is a Base64-encoded JSON string specifying the action for the receiving contract.
  • The receiving contract must implement the CW20 receive interface to handle incoming tokens.
  • This feature enables complex multi-contract interactions and delegated token management.

Update marketing

The update marketing operation allows the designated marketing address to modify the marketing-related information associated with the token. This feature enables keeping the token's metadata current and relevant.

To update marketing information, use the following command structure:

archway contracts execute <contract-name> --args '{
  "update_marketing": {
    "project": "<new_project_name>",
    "description": "<new_description>",
    "marketing": "<new_marketing_address>"
  }
}'

Replace:

  • <contract-name> with your token contract's name
  • <new_project_name> with the updated project name (optional)
  • <new_description> with the updated project description (optional)
  • <new_marketing_address> with the new marketing address (optional)

Example:

archway contracts execute my-cw20-token --args '{
  "update_marketing": {
    "project": "Updated CW20 Token",
    "description": "An enhanced version of our CW20 token",
    "marketing": "archway1newmarketing..."
  }
}'

Important notes:

  • Only the account set as the marketing address can execute this command.
  • You can update any combination of the fields; omitted fields will remain unchanged.
  • The marketing address can be updated to a new address if needed.
  • This operation allows for keeping token information up-to-date without altering the core token functionality.

The upload logo operation allows the designated marketing address to set or update the visual logo for the token. This logo can be displayed in wallets, exchanges, and other interfaces that interact with your CW20 token, enhancing its visual identity and recognition.

To upload or update the logo, use the following command structure:

archway contracts execute <contract-name> --args '{
  "upload_logo": {
    "url": "<logo_url>"
  }
}'

Replace:

  • <contract-name> with your token contract's name
  • <logo_url> with the URL of the new logo image

Example:

archway contracts execute my-cw20-token --args '{
  "upload_logo": {
    "url": "https://example.com/path/to/logo.png"
  }
}'

Important notes:

  • Only the account set as the marketing address can execute this command.
  • The logo should be a publicly accessible image file (PNG format is recommended).
  • Ensure the logo URL is stable and the image is of appropriate size and format for various displays.
  • Some platforms may have specific requirements for token logos, so consider these when selecting your image.
  • This operation updates only the logo URL; other marketing information remains unchanged.

Update minter

The update minter operation allows changing the account that has the authority to mint new tokens. This function is crucial for managing the controlled issuance of new tokens and is typically restricted to the current minter or a designated admin address.

To update the minter, use the following command structure:

archway contracts execute <contract-name> --args '{
  "update_minter": {
    "new_minter": "<new_minter_address>"
  }
}'

Replace:

  • <contract-name> with your token contract's name
  • <new_minter_address> with the address of the new minter

Example:

archway contracts execute my-cw20-token --args '{
  "update_minter": {
    "new_minter": "archway1newminter..."
  }
}'

Important notes:

  • Only the current minter can execute this command, unless otherwise specified in the contract.
  • The new minter will have the ability to mint new tokens, potentially affecting the total supply.
  • If you want to remove the minting capability entirely, you can set the new_minter to null.
  • This operation doesn't affect the existing token supply or other contract parameters.
  • Changing the minter is a significant action that can impact the token's economics, so use it cautiously.