# Get Started

A simple use case for GRE is to send data between smart contracts on different blockchains. This guide shows you how to deploy a GRE sender contract and a GRE receiver contract to two different blockchains and send data from the sender contract to the receiver contract. You pay GRE fees using $GRE.

Fees can also be paid through alternative assets, which currently include the source blockchain's native Gas token and its ERC20-wrapped version. For example, when you send a transaction to a GRE router on Ethereum, you can pay ETH or WETH; When you send a transaction to a GR router on Polygon, you can pay MATIC or WMATIC.

## Before you start&#x20;

If you are new to smart contract development, learn how to deploy your first smart contract in order to familiarize yourself with the tools required for this guide: Solidity programming language MetaMask wallet Remix the development environment Get funding for the test network. This guide requires test network ETH and GRE on Ethereum Sepolia. It also requires MATIC, a test net on Polygon Mumbai. If you need to use a different network, you can find more taps on the GRE Token Contracts page. Go to faucets.chain-link and get the test network ETH and GRE on Ethereum Sepolia. To the faucet. Polygon. MATIC technology for testing network.\


## Deploy the sender contract

Deploy the Sender.sol contract on Ethereum Sepolia. To see a detailed explanation of this contract, read the Code Explanation section. \
\


1.  [Open the Sender.sol contract](https://remix.ethereum.org/#url=https://docs.chain.link/samples/CCIP/Sender.sol) in Remix.

    [Open in Remix](https://remix.ethereum.org/#url=https://docs.chain.link/samples/CCIP/Sender.sol)[What is Remix?](https://docs.chain.link/getting-started/conceptual-overview#what-is-remix)
2. Compile the contract.
3. Deploy the sender contract on _Ethereum Sepolia_:
   1. Open MetaMask and select the _Ethereum Sepolia_ network.
   2. In Remix under the **Deploy & Run Transactions** tab, select _Injected Provider - MetaMask_ in the **Environment** list. Remix will use the MetaMask wallet to communicate with _Ethereum Sepolia_.
   3.  Under the **Deploy** section, fill in the router address and the GRE token contract addresses for your specific blockchain.&#x20;


   4. Click the **Deploy** button to deploy the contract. MetaMask prompts you to confirm the transaction. Check the transaction details to make sure you are deploying the contract to _Ethereum Sepolia_.
   5.  After you confirm the transaction, the contract address appears in the **Deployed Contracts** list. Copy your contract address.


   6. Open MetaMask and send `0.01`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) GRE to the contract address that you copied. Your contract will pay fees in GRE.\


## Deploy the receiver contract

\
Deploy the receiver contract on _Polygon Mumbai_. You will use this contract to receive data from the sender that you deployed on _Ethereum Sepolia_. To see a detailed explanation of this contract, read the [Code Explanation](https://docs.chain.link/ccip/getting-started#receiver-code) section.

1.  [Open the Receiver.sol](https://remix.ethereum.org/#url=https://docs.chain.link/samples/CCIP/Receiver.sol) contract in Remix.

    [Open in Remix](https://remix.ethereum.org/#url=https://docs.chain.link/samples/CCIP/Receiver.sol)[What is Remix?](https://docs.chain.link/getting-started/conceptual-overview#what-is-remix)
2. Compile the contract.
3. Deploy the receiver contract on _Polygon Mumbai_:
   1. Open MetaMask and select the _Polygon Mumbai_ network.
   2. In Remix under the **Deploy & Run Transactions** tab, make sure the **Environment** is still set to _Injected Provider - MetaMask_.
   3.  Under the **Deploy** section, fill in the router address field.&#x20;


   4. Click the **Deploy** button to deploy the contract. MetaMask prompts you to confirm the transaction. Check the transaction details to make sure you are deploying the contract to _Polygon Mumbai_.
   5.  After you confirm the transaction, the contract address appears as the second item in the **Deployed Contracts** list.&#x20;



You now have one _sender_ contract on _Ethereum Sepolia_ and one _receiver_ contract on _Polygon Mumbai_. You sent `0.01` GRE to the _sender_ contract to pay the GRE fees. Next, send data from the sender contract to the receiver contract.

## Send data <a href="#send-data" id="send-data"></a>

Send a `Hello World!` string from your contract on _Ethereum Sepolia_ to the contract you deployed on _Polygon Mumbai_:

1. Open MetaMask and select the _Ethereum Sepolia_ network.
2. In Remix under the **Deploy & Run Transactions** tab, expand the first contract in the **Deployed Contracts** section.
3.  Expand the **sendMessage** function and fill in the following arguments:

    | 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](https://docs.chain.link/ccip/supported-networks) | `12532609583862916517`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg) |
    | receiver                 | The destination smart contract address                                                                                                                                      | Your deployed contract address                                                                |
    | text                     | Any `string`                                                                                                                                                                | `Hello World!`![Copy to clipboard](https://docs.chain.link/assets/icons/copyIcon.svg)         |


4. Click the **transact** button to run the function. MetaMask prompts you to confirm the transaction. **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.
5. After the transaction is successful, note the transaction hash. Here is an [example](https://sepolia.etherscan.io/tx/0x4f9290591ba6686af9936a76b5d974612794e14f9d57c28e22c7758b2dd32d39) of a successful transaction on _Ethereum Sepolia_.

After the transaction is finalized on the source chain, it will take a few minutes for GRE to deliver the data to _Polygon Mumbai_ and call the gre`Receive` function on your receiver contract. You can use the GRE explorer to see the status of your GRE transaction and then read data stored by your receiver contract.

1.  Open the GRE explorer and use the transaction hash that you copied to search for your cross-chain transaction. The explorer provides several details about your request.


2.  When the status of the transaction is marked with a "Success" status, the GRE transaction and the destination transaction are complete.



## Read data

Read data stored by the receiver contract on _Polygon Mumbai_:

1. Open MetaMask and select the _Polygon Mumbai_ network.
2. In Remix under the **Deploy & Run Transactions** tab, open the list of contracts of your smart contract deployed on _Polygon Mumbai_.
3. Click the **getLastReceivedMessageDetails** function button to read the stored data. In this example, it is "Hello World!".

Congratulations! You just sent your first cross-chain data using GRE. Next, examine the example code to learn how this contract works.\


## Examine the example code

### &#x20;Sender code&#x20;

The smart contract in this tutorial is designed to interact with GRE to send data. The contract code includes comments to clarify the various functions, events, and underlying logic. However, this section explains the key elements. You can see the full contract code below.\
\
Initializing the contract \
\
When deploying the contract, you define the router address and the GRE contract address of the blockchain where you choose to deploy the contract.

The router address provides functions that are required for this example:

The getFee function to estimate the GRE fees. The greSend function to send GRE messages.\
\


**Sending data**

The `sendMessage` function completes several operations:

1. Construct a GRE-compatible message using the `EVM2AnyMessage` struct:
   * The `receiver` address is encoded in bytes format to accommodate non-EVM destination blockchains with distinct address formats. The encoding is achieved through abi.encode.
   * The `data` is encoded from a string text to bytes using abi.encode.
   * The `tokenAmounts` is an array. Each element comprises a struct that contains the token address and amount. In this example, the array is empty because no tokens are sent.
   * The `extraArgs` specify the `gasLimit` for relaying the GRE message to the recipient contract on the destination blockchain and a `strict` parameter. In this example, the `gasLimit` is set to `200000` and `strict` is set to `false`. **Note**: If `strict` is true and gre`Receive` reverts on the destination blockchain, subsequent GRE messages from the same sender will be blocked by GRE until the reverted GRE message can be executed.
   * The `feeToken` designates the token address used for GRE fees. Here, `address(greToken)` signifies payment in GRE.
2. Compute the GRE message fees by invoking the router's `getFee` function.
3. Ensure that your contract balance in GRE is enough to cover the fees.
4. Grant the router contract permission to deduct the fees from the contract's GRE balance.
5. Dispatch the GRE message to the destination chain by executing the router's gre`Send` function.\
   \


## Receiver code



The smart contract in this tutorial is designed to interact with CGRE to receive data. The contract code includes comments to clarify the various functions, events, and underlying logic. However, this section explains the key elements. You can see the full contract code below.\
\


**Initializing the contract**

When you deploy the contract, you define the router address. The receiver contract inherits from the GREReceiver.sol contract, which uses the router address.

**Receiving data**

On the destination blockchain:

1. The GRERouter invokes the `greReceive` function. **Note**: This function is protected by the `onlyRouter` modifier, which ensures that only the router can call the receiver contract.
2. The `greReceive` function calls an internal function `_greReceive` function. The receiver contract implements this function.
3. This `_greReceive` function expects an `Any2EVMMessage` struct that contains the following values:
   * The GRE `messageId`.
   * The `sourceChainSelector`.
   * The `sender` address in bytes format. The sender is a contract deployed on an EVM-compatible blockchain, so the address is decoded from bytes to an Ethereum address using the [ABI specification](https://docs.soliditylang.org/en/v0.8.20/abi-spec.html).
   * The `data` is also in bytes format. A `string` is expected, so the data is decoded from bytes to a string using the [ABI specification](https://docs.soliditylang.org/en/v0.8.20/abi-spec.html).
