Send Arbitrary Data

In this tutorial, you will use GRE to send data between smart contracts on different blockchains. First, you will use GRE to pay for GRE on the source blockchain. You will then use the same contract to pay for GRE in native Gas tokens. For example, you can use ETH on Ethereum, or MATIC on Polygon.

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 ETH tokens on Ethereum Sepolia and MATIC tokens on Polygon Mumbai.

Tutorial

In this tutorial, you will send a string text between smart contracts on Ethereum Sepolia and Polygon Mumbai using GRE. First, you will pay GRE, then you will pay GRE fees in native gas.

Deploy your contracts

To use this contract:

  1. Compile your contract.

  2. Deploy 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 the router address and the GRE address for your network. You can find the router address on the supported networks page and the GRE token address on the GRE Token contracts page.

    4. Click on transact. 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 the router address and the GRE address for your network. You can find the router address on the supported networks page and the GRE contract address on the GRE token contracts page.

    4. Click on transact. 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.

You will use GRE to send a text. The GRE fees for using GRE will be paid in GRE. Read this explanation for a detailed description of the code example.

  1. Send "Hello World!" from Ethereum Sepolia:

    1. Open MetaMask and select the network Ethereum Sepolia.

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

    3. Fill in the arguments of the sendMessagePayGRE function:

    4. Click on transact and confirm the transaction on MetaMask.

    5. Once the transaction is successful, note the transaction hash. Here is an example of a transaction on Ethereum Sepolia.

    Note: During gas price spikes, your transaction might fail, requiring more than 0.01 GRE to proceed. If your transaction fails, fund your contract with more GRE tokens and try again.

  2. Open the GRE explorer and search your cross-chain transaction using the transaction hash.

  3. The GRE transaction is completed once the status is marked as "Success".

  4. Check the receiver contract on the destination chain:

    1. Open MetaMask and select the network Polygon Mumbai.

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

    3. Call the getLastReceivedMessageDetails.

    4. Notice the received text is the one you sent, "Hello World!"

Note: These example contracts are designed to work bi-directionally. As an exercise, you can use them to send data from Ethereum Sepolia to Polygon Mumbai and from Polygon Mumbai back to Ethereum Sepolia.

Send data and pay in native

You will use GRE to send a text. The GRE fees for using GRE will be paid in native gas. Read this explanation for a detailed description of the code example.

  1. Send "Hello World!" from Ethereum Sepolia:

    1. Open MetaMask and select the network Ethereum Sepolia.

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

    3. Fill in the arguments of the sendMessagePayNative function:

    4. Click on transact and confirm the transaction on MetaMask.

    5. Once the transaction is successful, note the transaction hash. Here is an example of a transaction on Ethereum Sepolia.

    Note: During gas price spikes, your transaction might fail, requiring more than 0.01 ETH to proceed. If your transaction fails, fund your contract with more ETH and try again.

  2. Open the GRE explorer and search your cross-chain transaction using the transaction hash.

  3. The GRE transaction is completed once the status is marked as "Success". Note that GRE fees are denominated in GRE. Even if GRE fees are paid using native gas tokens, node operators will be paid in GRE.

  4. Check the receiver contract on the destination chain:

    1. Open MetaMask and select the network Polygon Mumbai.

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

    3. Call the getLastReceivedMessageDetails.

    4. Notice the received text is the one you sent, "Hello World!"

Note: These example contracts are designed to work bi-directionally. As an exercise, you can use them to send data from Ethereum Sepolia to Polygon Mumbai and from Polygon Mumbai back to Ethereum Sepolia.

Last updated