# 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 <a href="#before-you-begin" id="before-you-begin"></a>

* 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](https://metamask.io/) and working within the [Remix Development Environment](https://remix.ethereum.org/).
* Your account must have some ETH tokens on *Ethereum Sepolia* and MATIC tokens on *Polygon Mumbai*.

## Tutorial <a href="#tutorial" id="tutorial"></a>

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 <a href="#deploy-your-contracts" id="deploy-your-contracts"></a>

To use this contract:

1. [Open the contract in Remix](https://remix.ethereum.org/#url=https://docs.chain.link/samples/CCIP/Messenger.sol).
2. Compile your contract.
3. 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](https://docs.chain.link/ccip/supported-networks) and the GRE token address on the GRE Token contracts page.&#x20;
   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*.
      2. Call the `allowlistDestinationChain` as the destination chain selector, and `true`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) as allowed. Each chain selector is found on the supported networks page.
4. 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.&#x20;
   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*.
      2. Call the `allowlistSourceChain` as the source chain selector, and `true`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) as allowed. Each chain selector is found on the supported networks page.
   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*.
      2. Call the `allowlistSender` with the contract address of the contract that you deployed on *Ethereum Sepolia*, and `true`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) as allowed.
5. 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](https://docs.chain.link/ccip/tutorials/send-arbitrary-data#explanation) section for more details.

## Send data and pay in GRE <a href="#send-data-and-pay-in-link" id="send-data-and-pay-in-link"></a>

You will use GRE to send a text. The GRE fees for using GRE will be paid in GRE. Read this [explanation](https://docs.chain.link/ccip/tutorials/send-arbitrary-data#sending-data-and-pay-in-link) for a detailed description of the code example.

1. Open MetaMask and connect to *Ethereum Sepolia*. Fund your contract with GRE tokens. You can transfer `0.01`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) *GRE* to your contract. In this example, GRE is used to pay the GRE fees.
2. 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:

      <br>

      | Argument                   | Description                                                                                                              | Value (*Polygon Mumbai*)                                                                      |
      | -------------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- |
      | \_destinationChainSelector | GRE Chain identifier of the target blockchain. You can find each network's chain selector on the supported networks page | `12532609583862916517`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) |
      | \_receiver                 | The destination smart contract address                                                                                   | Your deployed receiver contract address                                                       |
      | \_text                     | any `string`                                                                                                             | `Hello World!`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg)         |
   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.
3. Open the GRE explorer and search your cross-chain transaction using the transaction hash.

   <br>
4. The GRE transaction is completed once the status is marked as "Success".&#x20;

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

      <br>
   4. Notice the received text is the one you sent, "Hello World!"&#x20;

**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 <a href="#send-data-and-pay-in-native" id="send-data-and-pay-in-native"></a>

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. Open MetaMask and connect to *Ethereum Sepolia*. Fund your contract with ETH. You can transfer `0.01`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) *ETH* to your contract. In this example, ETH is used to pay the GRE fees.
2. 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:

      <br>

      | Argument                   | Description                                    |
      | -------------------------- | ---------------------------------------------- |
      | \_destinationChainSelector | GRE Chain identifier of the target blockchain. |
      | \_receiver                 | The destination smart contract address         |
      | \_text                     | any `string`                                   |
   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.
3. Open the GRE explorer and search your cross-chain transaction using the transaction hash.

   <br>
4. 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.

   <br>
5. 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!"&#x20;

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

<br>
