- Docs
- Developers
- Execute transactions
Execute Transactions
This section of the guide focuses on executing various transactions using the CW20-ICS20 contract. The CW20-ICS20 contract facilitates several key operations:
- Receive: This function is triggered when a CW20 token is sent to the contract, initiating a predefined action within the contract itself.
- Transfer: Supports the transfer of exactly one type of native token across chains via IBC.
- Allow: Managed by an admin account, this command permits a new CW20 token to be accepted and handled by the contract. It's essential for integrating new tokens into the system.
- UpdateAdmin: This command allows for the transfer of administrative control of the contract, but can only be executed by the current admin.
In the following sections, we'll explore how to execute these transactions and their specific use cases.
Receive
The Receive function is automatically triggered when CW20 tokens are sent to the contract, enabling the contract to perform additional actions based on the received message. Here's an example of how to execute this function:
archwayd tx wasm execute CW20_CONTRACT_ADDRESS \'{"send": {"contract": "CW20_ICS20_CONTRACT_ADDRESS", "amount": "AMOUNT", "msg": "BASE64_ENCODED_MESSAGE"}}' \--from <my-wallet> \--node https://rpc.constantine.archway.io:443 \--chain-id constantine-3 \--gas auto \--gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') \--gas-adjustment 1.3
Replace the following placeholders with your specific values:
CW20_CONTRACT_ADDRESS
: The address of the CW20 token contractCW20_ICS20_CONTRACT_ADDRESS
: The address of your CW20-ICS20 contractAMOUNT
: The amount of tokens to sendBASE64_ENCODED_MESSAGE
: Your base64 encoded message<my-wallet>
: Your wallet address
Note: This command sends CW20 tokens to the CW20-ICS20 contract, which then triggers the Receive function. The actual Receive function is internal to the contract and not directly called by the user.
An example
A possible BASE64_ENCODED_MESSAGE
for a receive transaction would typically be an IBC transfer instruction. Here's an example:
- First, let's consider the JSON structure of an IBC transfer message:
{ "channel": "channel-0", "remote_address": "cosmos1...", "timeout": 1800}
This message instructs the contract to:
- Use "channel-0" for the IBC transfer
- Send the tokens to the "cosmos1..." address on the destination chain
- Set a timeout of 1800 seconds (30 minutes) for the IBC transfer
- Now, we need to encode this JSON message in Base64. Here's how you could do it:
echo '{"channel":"channel-0","remote_address":"cosmos1...","timeout":1800}' | base64
This command would output something like:
eyJjaGFubmVsIjoiY2hhbm5lbC0wIiwicmVtb3RlX2FkZHJlc3MiOiJjb3Ntb3MxLi4uIiwidGltZW91dCI6MTgwMH0=
- You would then use this Base64 encoded string as your BASE64_ENCODED_MESSAGE in the receive transaction.
So, a complete example of the send transaction (which triggers the receive function) might look like this:
archwayd tx wasm execute CW20_CONTRACT_ADDRESS \'{"send": {"contract": "CW20_ICS20_CONTRACT_ADDRESS", "amount": "1000000", "msg": "eyJjaGFubmVsIjoiY2hhbm5lbC0wIiwicmVtb3RlX2FkZHJlc3MiOiJjb3Ntb3MxLi4uIiwidGltZW91dCI6MTgwMH0="}}' \--from <my-wallet> \--node https://rpc.constantine.archway.io:443 \--chain-id constantine-3 \--gas auto \--gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') \--gas-adjustment 1.3
This would send 1,000,000 tokens (adjust the decimal places as needed for your specific token) to the CW20-ICS20 contract, instructing it to transfer these tokens via IBC to the specified address on the destination chain.
Transfer
The Transfer function in the CW20-ICS20 contract is used to initiate an IBC transfer of tokens. The structure of the TransferMsg is as follows:
#[cw_serde]pub struct TransferMsg { pub channel: String, pub remote_address: String, pub timeout: Option<u64>, pub memo: Option<String>,}
Here's an example of how to use this function:
archwayd tx wasm execute cw20_ics20_contract_address \'{ "transfer": { "channel": "channel-0", "remote_address": "cosmos1x23y45z6p78qw9er0uh", "timeout": 3600, "memo": "Payment for services" }}' \--amount 1000000utoken \--from <my-wallet> \--node https://rpc.constantine.archway.io:443 \--chain-id constantine-3 \--gas auto \--gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') \--gas-adjustment 1.3
Replace the following placeholders with your specific values:
cw20_ics20_contract_address
: The address of your CW20-ICS20 contractcosmos1x23y45z6p78qw9er0uh
: The recipient's address on the destination chain1000000utoken
: The amount and denomination of tokens to transfer (adjust as needed)<my-wallet>
: Your wallet address
This command:
- Initiates a transfer of 1,000,000 utoken via IBC
- Uses "channel-0" for the IBC transfer
- Specifies the recipient's address on the destination chain
- Sets a timeout of 3600 seconds (1 hour) for the IBC transfer
- Includes an optional memo "Payment for services"
Note:
- The
--amount
flag is used to specify the tokens being sent. Adjust the amount and denomination according to your needs. - The
timeout
andmemo
fields are optional. Iftimeout
is not specified, the contract will use its default timeout. - This structure is used when the contract receives tokens via the
Receive
function. For direct transfers of native tokens, you would use this message structure in conjunction with the--amount
flag.
Allow
The Allow transaction is designed to grant permission for a specific CW20 token to be sent through the contract. This action is crucial for enhancing the flexibility and functionality of the contract by enabling it to interact with multiple types of CW20 tokens.
To execute an Allow transaction, use the following command format with archwayd
:
archwayd tx wasm execute CW20_ICS20_CONTRACT_ADDRESS \'{ "allow": { "contract": "TOKEN_CONTRACT_ADDRESS", "gas_limit": 200000 }}' \--from <my-wallet> \--node https://rpc.constantine.archway.io:443 \--chain-id constantine-3 \--gas auto \--gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') \--gas-adjustment 1.3
Parameters:
CW20_ICS20_CONTRACT_ADDRESS
: The address of your CW20-ICS20 contractTOKEN_CONTRACT_ADDRESS
: The contract address of the CW20 token that is being authorized to be sent via the CW20-ICS20 contractgas_limit
: An optional parameter to set a gas limit for operations with this token (default is unlimited)<my-wallet>
: Your wallet address
Note:
- Only the contract admin can execute this command.
- The
gas_limit
is optional. If not provided, operations with this token will have unlimited gas. - You can find more details about the implementation in the cw20-ics20 contract source code.
This command allows the specified CW20 token to be sent through the CW20-ICS20 contract, expanding the range of tokens that can be transferred via IBC using this contract.
UpdateAdmin
The UpdateAdmin transaction changes the administrator of the specified CW20-ICS20 contract to a new address, effectively updating the contract's access control settings.
To execute an UpdateAdmin transaction, use the following command format with archwayd
:
archwayd tx wasm execute CW20_ICS20_CONTRACT_ADDRESS \'{ "update_admin": { "admin": "NEW_ADMIN_ADDRESS" }}' \--from <my-wallet> \--node https://rpc.constantine.archway.io:443 \--chain-id constantine-3 \--gas auto \--gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') \--gas-adjustment 1.3
Parameters:
CW20_ICS20_CONTRACT_ADDRESS
: The address of your CW20-ICS20 contractNEW_ADMIN_ADDRESS
: The wallet address of the new administrator who will be granted administrative control over the contract<my-wallet>
: Your wallet address (must be the current admin)
Note:
- Only the current contract admin can execute this command.
- This action transfers all administrative privileges to the new admin address.
- Exercise caution when using this function, as it changes who has control over the contract.
- You can find more details about the implementation in the cw20-ics20 contract source code.