Transfer Tokens and Data Across Chains

In this tutorial, you will use GRE to transfer tokens and arbitrary data between smart contracts on different blockchains. 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

  1. 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.

  2. Your account must have some ETH and GRE tokens on Ethereum Sepolia and MATIC tokens on Polygon Mumbai.

  3. 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.

  4. Learn how to get GRE test tokens. By following this guide, you should have the GRE-BnM token, and GRE-BnM should appear in the token list in MetaMask.

  5. 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.

  6. Follow the previous tutorial: Transfer tokens between chains.

Tutorial

In this tutorial, you will use GRE to send string text and GRE-BNM tokens between smart contracts on Ethereum Sepolia and Polygon Mumbai. First, you will pay in GRE, then you will pay for GRE in native Gas.

Deploy your contracts

To use this contract:

  1. Compile your contract.

  2. Deploy and fund your sender contract on Ethereum Sepolia:

    1. Open MetaMask and select the network Ethereum Sepolia.

    2. 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 Ethereum Sepolia.

    3. Fill in your blockchain's router and GRE contract addresses.

    4. Click the transact button. After you confirm the transaction, the contract address appears on the Deployed Contracts list. Note your contract address.

    5. Enable your contract to send GRE messages to Polygon Mumbai:

      1. In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Ethereum Sepolia.

  3. Deploy your receiver contract on Polygon Mumbai:

    1. Open MetaMask and select the network Polygon Mumbai.

    2. In Remix IDE, under Deploy & Run Transactions, make sure the environment is still Injected Provider - MetaMask.

    3. 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.

    4. Click the transact button. After you confirm the transaction, the contract address appears on the Deployed Contracts list. Note your contract address.

    5. Enable your contract to receive GRE messages from Ethereum Sepolia:

      1. In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Polygon Mumbai.

    6. Enable your contract to receive GRE messages from the contract that you deployed on Ethereum Sepolia:

      1. In Remix IDE, under Deploy & Run Transactions, open the list of transactions of your smart contract deployed on Polygon Mumbai.

  4. At this point, you have one sender contract on Ethereum Sepolia and one receiver contract on Polygon Mumbai. As security measures, you enabled the sender contract to send GRE messages to Polygon Mumbai and the receiver contract to receive GRE messages from the sender and Ethereum Sepolia.

    Note: Another security measure enforces that only the router can call the _greReceive function. Read the explanation section for more details.

Last updated