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.
-
Open the Remix IDE in your browser.
-
Create a new workspace.
-
Copy the content of the Test CCIP Local Simulator contract into a new file in the workspace.
undefined -
Copy the content of the Sender contract into a new file in the workspace.
undefined -
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
-
Compile the contracts.
-
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.
-
Deploy the CCIP local simulator:
-
Select the
TestCCIPLocalSimulator.solfile in the file explorer. -
In the Contract drop-down list, select
CCIPLocalSimulator. -
Click the Deploy button.
-
The
CCIPLocalSimulatoris shown in the Deployed Contracts section. -
In the list of functions, click the
configurationfunction to retrieve the configuration details for the pre-deployed contracts and services needed for local CCIP simulations:
-
-
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:
- Select
LinkTokenin the Contract drop-down list. - Fill in the At Address field with the address of the
LINKtoken contract from theCCIPLocalSimulatorconfiguration. - Click the At Address button.
The
LinkTokencontract is shown in the Deployed Contracts section. - Select
-
Deploy the
Sender.solcontract:- Select the
Sender.solfile in the file explorer. - In the Contract drop-down list, select
Sender. - Under the Deploy section, fill in the constructor parameters:
_router: The address of thesourceRoutercontract from theCCIPLocalSimulatorconfiguration._link: The address of theLINKtoken contract from theCCIPLocalSimulatorconfiguration.
- Click the Deploy button.
The
Sendercontract is shown in the Deployed Contracts section. - Select the
-
Deploy the
Receiver.solcontract:- Select the
Receiver.solfile in the file explorer. - In the Contract drop-down list, select
Receiver. - Under the Deploy section, fill in the constructor parameters:
_router: The address of thedestinationRoutercontract from theCCIPLocalSimulatorconfiguration.
- Click the Deploy button.
The
Receivercontract is shown in the Deployed Contracts section. - Select the
Transfer data from the sender to the receiver
-
Fund the sender contract with LINK tokens to pay for CCIP fees:
- Copy the address of the
Sendercontract from the Deployed Contracts section. - In the
CCIPLocalSimulatorcontract, fill in therequestLinkFromFaucetfunction with the following inputs:to: The address of theSendercontract.amount: The amount of LINK tokens to transfer. For instance:1000000000000000000.
- Click the Transact button.
- Copy the address of the
-
Send data from the sender contract to the receiver contract:
-
Copy the address of the
Receivercontract from the Deployed Contracts section. -
In the
Sendercontract, fill in thesendMessagefunction with:destinationChainSelector: The destination chain selector. You can find it in theCCIPLocalSimulatorconfiguration.receiver: The address of theReceivercontract.text: The text to send. For instanceHello!.
-
Remix IDE fails to estimate the gas properly for the
sendMessagefunction. To work around this, you need to set the gas limit manually to3000000: -
Click the Transact button.
-
-
Check the receiver contract to verify the data transfer:
-
In the
Receivercontract, click on thegetLastReceivedMessageDetailsfunction. -
The
getLastReceivedMessageDetailsfunction returns the text sent from theSendercontract:
-
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.