Manual Execution
This tutorial is similar to the programmable token transfers example. It demonstrates the use of Chainlink CCIP for transferring tokens and arbitrary data between smart contracts on different blockchains. A distinctive feature of this tutorial is that we intentionally set a very low gas limit when using CCIP to send our message. This low gas limit is designed to cause the execution on the destination chain to fail, providing an opportunity to demonstrate the manual execution feature. Here's how you will proceed:
- Initiate a Transfer: You'll transfer tokens and arbitrary data from your source contract on Avalanche Fuji to a receiver contract on Ethereum Sepolia. You will notice that the CCIP message has a very low gas limit, causing the execution on the receiver contract to fail.
- Failure of CCIP Message Delivery: Once the transaction is finalized on the source chain (Avalanche Fuji), CCIP will deliver your message to the receiver contract on the destination chain (Ethereum Sepolia). You can follow the progress of your transaction using the CCIP explorer. Here, you'll observe that the execution on the receiver contract failed due to the low gas limit.
- Manual Execution via CCIP Explorer: Using the CCIP explorer, you will override the previously set gas limit and retry the execution. This process is referred to as manual execution.
- Confirm Successful Execution: After manually executing the transaction with an adequate gas limit, you'll see that the status of your CCIP message is updated to successful. This indicates that the tokens and data were correctly transferred to the receiver contract.
Before you begin
- You should understand how to write, compile, deploy, and fund a smart contract. If you need to brush up on the basics, read this tutorial, which will guide you through using the Solidity programming language, interacting with the MetaMask wallet and working within the Remix Development Environment.
- Your account must have some AVAX and LINK tokens on Avalanche Fuji and ETH tokens on Ethereum Sepolia. Learn how to Acquire testnet LINK.
- Check the CCIP Directory to confirm that the tokens you will transfer are supported for your lane. In this example, you will transfer tokens from Avalanche Fuji to Ethereum Sepolia so check the list of supported tokens here.
- Learn how to acquire CCIP test tokens. Following this guide, you should have CCIP-BnM tokens, and CCIP-BnM should appear in the list of your tokens in MetaMask.
- Learn how to fund your contract. This guide shows how to fund your contract in LINK, but you can use the same guide for funding your contract with any ERC20 tokens as long as they appear in the list of tokens in MetaMask.
- Follow the previous tutorial: Transfer Tokens with Data to learn how to make programmable token transfers using CCIP.
- Create a free account on Tenderly. You will use Tenderly to investigate the failed execution of the receiver contract.
Tutorial
In this tutorial, you'll send a text string and CCIP-BnM tokens between smart contracts on Avalanche Fuji and Ethereum Sepolia using CCIP and pay transaction fees in LINK. The tutorial demonstrates setting a deliberately low gas limit in the CCIP message, causing initial execution failure on the receiver contract. You will then:
- Use the CCIP explorer to increase the gas limit.
- Manually retry the execution.
- Observe successful execution after the gas limit adjustment.
undefinedDeploy your contracts
To use this contract:
-
Compile your contract.
-
Deploy, fund your sender contract on Avalanche Fuji and enable sending messages to Ethereum Sepolia:
-
Open MetaMask and select the network Avalanche Fuji.
-
In Remix IDE, click on Deploy & Run Transactions and select Injected Provider - MetaMask from the environment list. Remix will then interact with your MetaMask wallet to communicate with Avalanche Fuji.
-
Fill in your blockchain's router and LINK contract addresses. The router address can be found on the CCIP Directory and the LINK contract address on the LINK token contracts page. For Avalanche Fuji:
- The router address is
0xF694E193200268f9a4868e4Aa017A0118C9a8177, - The LINK contract address is
0x0b9d5D9136855f6FEc3c0993feE6E9CE8a297846.
- The router address is
-
Click the transact button. After you confirm the transaction, the contract address appears on the Deployed Contracts list. Note your contract address.
-
Open MetaMask and fund your contract with CCIP-BnM tokens. You can transfer
0.002CCIP-BnM to your contract. -
Open MetaMask and fund your contract with LINK tokens. You can transfer
70LINK to your contract. In this example, LINK is used to pay the CCIP fees.Note: This transaction fee is significantly higher than normal due to gas spikes on Sepolia. To run this example, you can get additional testnet LINK from faucets.chain.link or use a supported testnet other than Sepolia.
-
Enable your contract to send CCIP messages to Ethereum Sepolia:
- In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Avalanche Fuji.
- Call the
allowlistDestinationChainwith16015286601757825753as the destination chain selector, andtrueas allowed. Each chain selector is found on the CCIP Directory.
-
-
Deploy your receiver contract on Ethereum Sepolia and enable receiving messages from your sender contract:
- Open MetaMask and select the network Ethereum Sepolia.
- In Remix IDE, under Deploy & Run Transactions, make sure the environment is still Injected Provider - MetaMask.
- Fill in your blockchain's router and LINK contract addresses. The router address can be found on the CCIP Directory and the LINK contract address on the LINK token contracts page. For Ethereum Sepolia:
- The router address is
0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59, - The LINK contract address is
0x779877A7B0D9E8603169DdbD7836e478b4624789.
- The router address is
- Click the transact button. After you confirm the transaction, the contract address appears on the Deployed Contracts list. Note your contract address.
- Enable your contract to receive CCIP messages from Avalanche Fuji:
- In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Ethereum Sepolia.
- Call the
allowlistSourceChainwith14767482510784806043as the source chain selector, andtrueas allowed. Each chain selector is found on the CCIP Directory.
- Enable your contract to receive CCIP messages from the contract that you deployed on Avalanche Fuji:
- In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Ethereum Sepolia.
- Call the
allowlistSenderwith the contract address of the contract that you deployed on Avalanche Fuji, andtrueas allowed.
At this point, you have one sender contract on Avalanche Fuji and one receiver contract on Ethereum Sepolia. As security measures, you enabled the sender contract to send CCIP messages to Ethereum Sepolia and the receiver contract to receive CCIP messages from the sender and Avalanche Fuji.
Transfer and Receive tokens and data and pay in LINK
You will transfer 0.001 CCIP-BnM and a text. The CCIP fees for using CCIP will be paid in LINK.
-
Send a string data with tokens from Avalanche Fuji:
-
Open MetaMask and select the network Avalanche Fuji.
-
In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Avalanche Fuji.
-
Fill in the arguments of the sendMessagePayLINK function:
Argument Value and Description _destinationChainSelector 16015286601757825753
CCIP Chain identifier of the destination blockchain (Ethereum Sepolia in this example). You can find each chain selector on the CCIP Directory._receiver Your receiver contract address at Ethereum Sepolia.
The destination contract address._text Hello World!
Anystring_token 0xD21341536c5cF5EB1bcb58f6723cE26e8D8E90e4
The CCIP-BnM contract address at the source chain (Avalanche Fuji in this example). You can find all the addresses for each supported blockchain on the CCIP Directory._amount 1000000000000000
The token amount (0.001 CCIP-BnM). -
Click on
transactand confirm the transaction on MetaMask. -
After the transaction is successful, record the transaction hash. Here is an example of a transaction on Avalanche Fuji.
-
-
Open the CCIP explorer and search your cross-chain transaction using the transaction hash. Note that the Gas Limit is 20000. In this example, the CCIP message ID is 0xf8dc098c832332ac59ccc73ee00b480975d8f122a2265c90a1ccc2cd52268770.
-
After a few minutes, the status will be updated to Ready for manual execution indicating that CCIP could not successfully deliver the message due to the initial low gas limit. At this stage, you have the option to override the gas limit.
-
You can also confirm that the CCIP message was not delivered to the receiver contract on the destination chain:
-
Open MetaMask and select the network Ethereum Sepolia.
-
In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Ethereum Sepolia.
-
Call the
getLastReceivedMessageDetailsfunction.
-
Observe that the returned data is empty: the received messageId is 0x0000000000000000000000000000000000000000000000000000000000000000, indicating no message was received. Additionally, the received text field is empty, the token address is the default 0x0000000000000000000000000000000000000000, and the token amount shows as 0.
-
Manual execution
Investigate the root cause of receiver contract execution failure
To determine if a low gas limit is causing the failure in the receiver contract's execution, consider the following methods:
-
Error analysis: Examine the error description in the CCIP explorer. An error labeled ReceiverError. This may be due to an out of gas error on the destination chain. Error code: 0x, often indicates a low gas issue.
-
Advanced Investigation Tool: For a comprehensive analysis, employ a sophisticated tool like Tenderly. Tenderly can provide detailed insights into the transaction processes, helping to pinpoint the exact cause of the failure.
To use Tenderly:
-
Copy the destination transaction hash from the CCIP explorer. In this example, the destination transaction hash is 0x9f5b50460a1ab551add15dc4b743c81df992e34bc8140bbbdc033de7043140f5.
-
Open Tenderly and search for your transaction. You should see an interface similar to the following:
-
Enable Full Trace then click on Reverts.
-
Notice the out of gas error in the receiver contract. In this example, the receiver contract is 0x47EAa31C9e2B1B1Ba19824BedcbE0014c15df15e.
Trigger manual execution
You will increase the gas limit and trigger manual execution:
-
In the CCIP explorer, connect your wallet, set the Gas limit override to
200000, and click on Trigger Manual Execution.
-
After you confirm the transaction on Metamask, the CCIP explorer shows you a confirmation screen.
-
Click on the Close button and observe the status marked as Success.
-
Check the receiver contract on the destination chain:
-
Open MetaMask and select the network Ethereum Sepolia.
-
In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Ethereum Sepolia.
-
Call the
getLastReceivedMessageDetailsfunction.
-
Notice the received messageId is 0xf8dc098c832332ac59ccc73ee00b480975d8f122a2265c90a1ccc2cd52268770, the received text is Hello World!, the token address is 0xFd57b4ddBf88a4e07fF4e34C487b99af2Fe82a05 (CCIP-BnM token address on Ethereum Sepolia) and the token amount is 1000000000000000 (0.001 CCIP-BnM).
-
Note: These example contracts are designed to work bi-directionally. As an exercise, you can use them to transfer tokens and data from Avalanche Fuji to Ethereum Sepolia and from Ethereum Sepolia back to Avalanche Fuji.
Explanation
The smart contract used in this tutorial is configured to use CCIP for transferring and receiving tokens with data, similar to the contract in the Transfer Tokens with Data section of that tutorial.
A key distinction in this tutorial is the intentional setup of a low gas limit of 20,000 for building the CCIP message. This specific gas limit setting is expected to fail the message delivery on the receiver contract in the destination chain:
Client.EVMExtraArgsV2({
gasLimit: 20_000
allowOutOfOrderExecution: true
})