# 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:

        \


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

    \

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

    \

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

#### 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:

        \


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

    \

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.

    \

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

\
