Using the CCIP local simulator in Remix IDE

In this guide, you will test the Chainlink CCIP getting started guide locally in Remix IDE. You will:

  • Deploy a CCIP sender contract
  • Deploy a CCIP receiver contract
  • Use the local simulator to send data from the sender contract to the receiver contract

Prerequisites

Remix IDE is an online development environment that allows you to write, deploy, and test smart contracts. By default Remix IDE does not persist the files that you open from an external source. To save files, you will need to manually create a workspace and copy the files into the workspace.

  1. Open the Remix IDE in your browser.

  2. Create a new workspace.

  3. Copy the content of the Test CCIP Local Simulator contract into a new file in the workspace.

    undefined
  4. Copy the content of the Sender contract into a new file in the workspace.

    undefined
  5. Copy the content of the Receiver contract into a new file in the workspace.

    undefined

At this point, you should have three files in your workspace:

  • TestCCIPLocalSimulator.sol: The file imports the Chainlink CCIP local simulator contract.

  • Sender.sol: The file contains the Sender contract that interacts with CCIP to send data to the Receiver contract.

  • Receiver.sol: The file contains the Receiver contract that receives data from the Sender contract.

Deploy the contracts

  1. Compile the contracts.

  2. Under the Deploy & Run Transactions tab, make sure Remix VM is selected in the Environment drop-down list. Remix will use a sandbox blockchain in the browser to deploy the contracts.

  3. Deploy the CCIP local simulator:

    1. Select the TestCCIPLocalSimulator.sol file in the file explorer.

    2. In the Contract drop-down list, select CCIPLocalSimulator.

    3. Click the Deploy button.

    4. The CCIPLocalSimulator is shown in the Deployed Contracts section.

    5. In the list of functions, click the configuration function to retrieve the configuration details for the pre-deployed contracts and services needed for local CCIP simulations:

  4. You will interact with the LINK token contract to fund the sender contract with LINK tokens. The LINK token contract is pre-deployed in the local simulator configuration, so you can simply load the LINK token contract instance:

    1. Select LinkToken in the Contract drop-down list.
    2. Fill in the At Address field with the address of the LINK token contract from the CCIPLocalSimulator configuration.
    3. Click the At Address button.

    The LinkToken contract is shown in the Deployed Contracts section.

  5. Deploy the Sender.sol contract:

    1. Select the Sender.sol file in the file explorer.
    2. In the Contract drop-down list, select Sender.
    3. Under the Deploy section, fill in the constructor parameters:
      • _router: The address of the sourceRouter contract from the CCIPLocalSimulator configuration.
      • _link: The address of the LINK token contract from the CCIPLocalSimulator configuration.
    4. Click the Deploy button.

    The Sender contract is shown in the Deployed Contracts section.

  6. Deploy the Receiver.sol contract:

    1. Select the Receiver.sol file in the file explorer.
    2. In the Contract drop-down list, select Receiver.
    3. Under the Deploy section, fill in the constructor parameters:
      • _router: The address of the destinationRouter contract from the CCIPLocalSimulator configuration.
    4. Click the Deploy button.

    The Receiver contract is shown in the Deployed Contracts section.

Transfer data from the sender to the receiver

  1. Fund the sender contract with LINK tokens to pay for CCIP fees:

    1. Copy the address of the Sender contract from the Deployed Contracts section.
    2. In the CCIPLocalSimulator contract, fill in the requestLinkFromFaucet function with the following inputs:
      • to: The address of the Sender contract.
      • amount: The amount of LINK tokens to transfer. For instance: 1000000000000000000.
    3. Click the Transact button.
  2. Send data from the sender contract to the receiver contract:

    1. Copy the address of the Receiver contract from the Deployed Contracts section.

    2. In the Sender contract, fill in the sendMessage function with:

      • destinationChainSelector: The destination chain selector. You can find it in the CCIPLocalSimulator configuration.
      • receiver: The address of the Receiver contract.
      • text: The text to send. For instance Hello!.
    3. Remix IDE fails to estimate the gas properly for the sendMessage function. To work around this, you need to set the gas limit manually to 3000000:

    4. Click the Transact button.

  3. Check the receiver contract to verify the data transfer:

    1. In the Receiver contract, click on the getLastReceivedMessageDetails function.

    2. The getLastReceivedMessageDetails function returns the text sent from the Sender contract:

Next steps

You have successfully tested the CCIP getting started guide within a few minutes using Remix IDE. Testing locally is useful to debug your contracts and fix any issues before testing them on testnets, saving you time and resources. As an exercise, you can try any of the CCIP guides using the local simulator in Remix IDE.

Get the latest Chainlink content straight to your inbox.