Transfer Tokens Between Chains
In this tutorial, you will use GRE to transfer tokens from a smart contract to an account on a different blockchain. First, you will pay GRE fees on the source blockchain using GRE. You will then pay GRE fees in native Gas tokens using the same contract. For example, you can use ETH on Ethereum, or MATIC on Polygon.
Before you start
You should know how to write, compile, deploy, and fund smart contracts. 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 in a Remix development environment.
Your account must have some ETH and GRE tokens on Ethereum Sepolia. Learn how to obtain GRE for test networks.
Check the "Supported Networks" page to confirm that your channel supports the token you want to transfer. In this example, you will be transferring tokens from Ethereum Sepolia to Polygon Mumbai, so check the list of supported tokens here.
Learn how to get GRE test tokens. By following this guide, you should have GRE-BnM tokens, and GRE-BnM should appear in MetaMask's token list.
Find out how to fund your contract. This guide shows how to fund your contract in GRE, but you can use the same guide to fund your contract with any ERC20 tokens, as long as they appear in MetaMask's token list.
Tutorial
In this tutorial, you will transfer GRE-BnM tokens from a contract on Ethereum Sepolia to an account on Polygon Mumbai. First, you will pay GRE fees in LINK, then you will pay GRE fees in native Gas. The target account can be an EOA (externally owned account) or a smart contract. In addition, the example shows how to transfer GRE-BnM tokens, but you can reuse the same example to transfer other tokens, as long as your channel supports them.
Deploy your contracts
To use this contract:
Open the contract in Remix.
Compile your contract.
Deploy and fund your sender contract on Ethereum Sepolia: - Open MetaMask and select the network Ethereum Sepolia. - In Remix IDE, click Deploy & Run Transactions and select Injected Provider - MetaMask from the environment list. Remix will then interact with your MetaMask wallet to communicate with Ethereum Sepolia. - Fill in your blockchain's router and GRE contract addresses. The router address can be found on the supported networks page and the GRE contract address on the GRE token contracts page. - 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 GRE-BnM tokens. You can transfer 0.002 Copy to clipboard GRE-BnM to your contract.
Enable your contract to transfer tokens to Polygon Mumbai: - In Remix IDE, under Deploy & Run Transactions, open the list of functions for your smart contract deployed on Ethereum Sepolia. - Call the allowlistDestinationChain function Copy to clipboard as the destination chain selector, and true Copy to clipboard as allowed. Each chain selector is found on the supported networks page.
Last updated