Exercise 2: Build Your First Cross-Chain NFT
Coding Time 🎉
CCIP Config Details
Chain Selector
CCIP Router Address
0x2a9c5afb0d0e4bab2bcdae109ec4b0c4be15a165
0x0bf3de8c5d3e8a2b34d2beeb17abfcebaf363a59
LINK Token Address
0xb1D4538B4571d411F07960EF2838Ce337FE1E80E
0x779877A7B0D9E8603169DdbD7836e478b4624789
Getting started
You can use Chainlink CCIP with any blockchain development framework. For this Masterclass, we prepared the steps for Hardhat, Foundry, and Remix IDE.
Let's create a new project
Make sure you have Node.js and NPM installed. To check, run the following command:
node -vnpm -vCreate a new folder and name it ccip-masterclass-3
mkdir ccip-masterclass-3Navigate to it
cd ccip-masterclass-3Create a hew Hardhat project by running:
npx hardhat initAnd then select "Create a TypeScript project".
Make sure you have Foundry installed. To check, run the following command:
forge --versionCreate a new folder and name it ccip-masterclass-3
mkdir ccip-masterclass-3Navigate to it
cd ccip-masterclass-3Create a hew Foundry project by running:
forge initNavigate to https://remix.ethereum.org/ and click the "Create new Workspace" button. Select "Blank" template and name the workspace as "CCIP Masterclass 3".
Alternatively, you can clone:
The @chainlink/contracts-ccip NPM package
To use Chainlink CCIP, you need to interact with Chainlink CCIP-specific contracts from the @chainlink/contracts-ccip NPM package.
To install it, follow steps specific to the development environment you will use for this Masterclass.
We will need a standard @chainlink/contracts NPM package for this Module as well, so let's install it too while we are here by running the following command:
Finally, for this exercise we will need to install and the @openzeppelin/contracts NPM package, as well. To do so, run:
Since Foundry is designed to run with Solidity, NPM packages, though usable, ,can be replaced with directly installying Solidity contract packages from Github source repositories. We will install Chainlink CCIP contracts and then the contracts for other Chainlink Services.
First the CCIP Contracts.
And after that set remappings in your foundry.toml or remappings.txt files to
Next we install the other Chainlink Services contracts by running the following command:
And set remmapings to
Finally, for this exercise we will need to install and the @openzeppelin/contracts NPM package, as well. To do so, run:
And set remappings to @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ in foundry.toml or remappings.txt files.
Create a new Solidity file, and paste the following content. It is an empty contract that just imports one of the contracts from the @chainlink/contracts-ccip package.
Compile it. If compiled successfully and new .deps/npm/@chainlink/contracts-ccip , .deps/npm/@chainlink/contracts and .deps/npm/@openzeppelin/contracts folders are generated, that means we imported all of the necessary packages into the Remix IDE Workspace.
Faucet
To pay for CCIP Fees you can use either LINK token or native/wrapped native asset on a given blockchain. For this exercise we will need at least 1 LINK or Arbitrum Sepolia testnet. To get it, navigate to the https://faucets.chain.link/arbitrum-sepolia

Develop xNFT smart contract
Create a new file inside the contracts folder and name it XNFT.sol
Compile your contract by running:
Create a new file inside the src folder and name it XNFT.sol
Create a new Solidity file by clicking on the "Create new file" button and name it XNFT.sol
Prepare for deployment
Follow the steps to add the necessary environment variables for deploying these contracts and sending your first CCIP Message.
This contract expects at least 0.8.20 Solidity version. It is very important to understand that with Solc version 0.8.20, the default EVM version is set to "Shanghai". A new opcode, PUSH0, was added to the Ethereum Virtual Machine in the Shanghai upgrade.
However, besides Ethereum, the majority of blockchains haven't included PUSH0 opcode.
That means the PUSH0 opcode can now be part of the contract's bytecode and if the chain you are working on does not support it, it will error with the "Invalid opcode" error.
To understand more, we highly encourage you to check this StackOverflow answer:
We are going to use the @chainlink/env-enc package for extra security. It encrypts sensitive data instead of storing them as plain text in the .env file by creating a new .env.enc file. Although it's not recommended to push this file online, if that accidentally happens, your secrets will still be encrypted.
Install the package by running the following command:
Set a password for encrypting and decrypting the environment variable file. You can change it later by typing the same command.
Now set the following environment variables: PRIVATE_KEY, Source Blockchain RPC URL, Destination Blockchain RPC URL. For this example, we are going to use Arbitrum Sepolia and Ethereum Sepolia.
To set these variables, type the following command and follow the instructions in the terminal:
After you are done, the .env.enc file will be automatically generated. If you want to validate your inputs, you can always run the next command:
Finally, expand the hardhat.config to support these two networks:
Create a new file and name it .env. Fill in your wallet's PRIVATE_KEY and RPC URLs for at least two blockchains. For this example, we are going to use Arbitrum Sepolia and Ethereum Sepolia.
Once that is done, to load the variables in the .env file, run the following command:
Finally, expand the foundry.toml to support these two networks:
Navigate to the "Solidity compiler" tab
Toggle the "Advanced Configurations" dropdown
Toggle the "EVM VERSION" dropdown menu and select "paris" instead of "default"
Navigate to the "Deploy & run transactions" tab and select the "Injected Provider - Metamask" option from the "Environment" dropdown menu.

If you are using Metamask wallet, the Ethereum Sepolia network should already came preinstalled. Make sure you added the Arbitrum Sepolia network.
Go to Chainlist.org and search for "arbitrum sepolia". Once you see the network with Chain ID 421614, click the "Add to Metamask" button.

Step 1) Deploy XNFT.sol to Ethereum Sepolia
Prepare Chain Selector and CCIP Router & LINK token addresses on Ethereum Sepolia. You can get them if you scroll to the beginning of this page, at CCIP Config Details
Navigate to the scripts folder and create new file named deployXNFT.ts
Run the deployment script:
Prepare Chain Selector and CCIP Router & LINK token addresses on Ethereum Sepolia. You can get them if you scroll to begging of this page, at CCIP Config Details
Option 1)
Deploy XNFT.sol smart contract by running:
Option 2)
Create a new smart contract under the script folder and name it XNFT.s.sol
Note that deployment of the XNFT smart contract is hard coded to Ethereum Sepolia for this example, but feel free to refactor the following deployment script to support other networks. You can check CCIP Starter Kit (Foundry version) for reference.
Deploy XNFT.sol smart contract by running:
Prepare Chain Selector and CCIP Router & LINK token addresses on Ethereum Sepolia. You can get them if you scroll to begging of this page, at CCIP Config Details
Open your Metamask wallet and switch to the Ethereum Sepolia network.
Open the XNFT.sol file.
Navigate to the "Solidity Compiler" tab and click the "Compile XNFT.sol" button.
Navigate to the "Deploy & run transactions" tab and select the "Injected Provider - Metamask" option from the "Environment" dropdown menu. Make sure that chainId is switched to 11155111 (if not, you may need to refresh the Remix IDE page in your browser).
Under the "Contract" dropdown menu, make sure that the "XNFT - XNFT.sol" is selected.
Locate the orange "Deploy" button. Provide 0x0bf3de8c5d3e8a2b34d2beeb17abfcebaf363a59 as the ccipRouterAddress , 0x779877A7B0D9E8603169DdbD7836e478b4624789 as the linkTokenAddress and 16015286601757825753 as the currentChainSelector.
Click the orange "Deploy"/"Transact" button.
Metamask notification will pop up. Sign the transaction.
Step 2) Deploy XNFT.sol to Arbitrum Sepolia
Prepare Chain Selector and CCIP Router & LINK token addresses on Arbitrum Sepolia. You can get them if you scroll to beginning of this page, at CCIP Config Details
Navigate to the scripts folder and create new file named deployXNFTArbitrum.ts
Run the deployment script:
Prepare Chain Selector and CCIP Router & LINK token addresses on Arbitrum Sepolia. You can get them if you scroll to begging of this page, at CCIP Config Details
Option 1)
Deploy XNFT.sol smart contract by running:
Option 2)
Create a new smart contract under the script folder and name it XNFTArbitrum.s.sol
Note that deployment of the XNFT smart contract is hard coded to Arbitrum Sepolia for this example, but feel free to refactor the following deployment script to support other networks. You can check CCIP Starter Kit (Foundry version) for reference.
Deploy XNFT.sol smart contract by running:
Prepare Chain Selector and CCIP Router & LINK token addresses on Arbitrum Sepolia. You can get them if you scroll to begging of this page, at CCIP Config Details
Open your Metamask wallet and switch to the Arbitrum Sepolia network.
Open the XNFT.sol file.
Navigate to the "Solidity Compiler" tab and click the "Compile XNFT.sol" button.
Navigate to the "Deploy & run transactions" tab and select the "Injected Provider - Metamask" option from the "Environment" dropdown menu. Make sure that chainId is switched to 421614 (if not, you may need to refresh the Remix IDE page in your browser).
Under the "Contract" dropdown menu, make sure that the "XNFT - XNFT.sol" is selected.
Locate the orange "Deploy" button. Provide 0x2a9c5afb0d0e4bab2bcdae109ec4b0c4be15a165 as the ccipRouterAddress , 0xb1D4538B4571d411F07960EF2838Ce337FE1E80E as the linkTokenAddress and 3478487238524512106 as the currentChainSelector.
Click the orange "Deploy"/"Transact" button.
Metamask notification will pop up. Sign the transaction.
Step 3) On Ethereum Sepolia, call enableChain function
Prepare:
The address of the address of the
XNFT.solsmart contract you previously deployed to Ethereum Sepolia;The address of the address of the
XNFT.solsmart contract you previously deployed to Arbitrum Sepolia;3478487238524512106, which is the CCIP Chain Selector for the Arbitrum Sepolia network, as the
chainSelectorparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract:
Create a new TypeScript file under the scripts folder and name it enableChain.ts
Call the function by running the following command:
Prepare:
The address of the address of the
XNFT.solsmart contract you previously deployed to Ethereum Sepolia;The address of the address of the
XNFT.solsmart contract you previously deployed to Arbitrum Sepolia;3478487238524512106, which is the CCIP Chain Selector for the Arbitrum Sepolia network, as the
chainSelectorparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract. Inside the scripts folder, create EncodeExtraArgs.s.sol and paste the following code:
Run:
Under the "Deployed Contracts" section, you should find the XNFT.sol contract you previously deployed to Ethereum Sepolia. Find the enableChain function and provide:
3478487238524512106, which is the CCIP Chain Selector for the Arbitrum Sepolia network, as the
chainSelectorparameter;The address of the address of the
XNFT.solsmart contract you previously deployed to Arbitrum Sepolia, asxNftAddressparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
Hit the "Transact" orange button.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract. Create EncodeExtraArgs.sol file and paste the following code:
Step 4) On Arbitrum Sepolia, call enableChain function
Prepare:
The address of the
XNFT.solsmart contract you previously deployed to Arbitrum Sepolia;The address of the address of the
XNFT.solsmart contract you previously deployed to Ethereum Sepolia, asxNftAddressparameter;16015286601757825753, which is the CCIP Chain Selector for the Ethereum Sepolia network, as thechainSelectorparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract:
Create a new TypeScript file under the scripts folder and name it enableChainArbitrum.ts
Call the function by running the following command:
Prepare:
The address of the address of the
XNFT.solsmart contract you previously deployed to Arbitrum Sepolia;The address of the address of the
XNFT.solsmart contract you previously deployed to Ethereum Sepolia, asxNftAddressparameter;16015286601757825753, which is the CCIP Chain Selector for the Ethereum Sepolia network, as thechainSelectorparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract. Inside the scripts folder, create EncodeExtraArgs.s.sol and paste the following code:
Run:
Under the "Deployed Contracts" section, you should find the XNFT.sol contract you previously deployed to Arbitrum Sepolia. Find the enableChain function and provide:
16015286601757825753, which is the CCIP Chain Selector for the Ethereum Sepolia network, as thechainSelectorparameter;The address of the address of the
XNFT.solsmart contract you previously deployed to Ethereum Sepolia, asxNftAddressparameter;0x97a657c90000000000000000000000000000000000000000000000000000000000030d40, which is the bytes version of CCIP extraArgs' default value with 200_000 gas set for gasLimit, asccipExtraArgsparameter.
Hit the "Transact" orange button.
If you would like to calculate this value by yourself, you can reuse the following helper smart contract. Create EncodeExtraArgs.sol file and paste the following code:
Step 5) On Arbitrum Sepolia, fund XNFT.sol with 3 LINK
To cover for CCIP fees, fund XNFT.sol with some amount of LINK, 3 should be more than enough for this demo. Obviously, for the sake of full functionality, you should fund XNFT.sol smart contract on other blockchains as well, so you can perform cross-chain transfers between all of them.

Step 6) On Arbitrum Sepolia, mint new xNFT
Create a new TypeScript file under the scripts folder and name it mint.ts
Call the function by running the following command:
Run:
Under the "Deployed Contracts" section, you should find the XNFT.sol contract you previously deployed to Arbitrum Sepolia. Find the mint function and hit the "Transact" orange button.
Step 7) On Arbitrum Sepolia, crossTransferFrom xNFT
Prepare:
Your EOA address, as the
fromparameter;The address of an EOA on other chain where you want to cross-transfer your NFT, can be your EOA address, as
toparameter;The ID of a xNFT you want to cross-transfer, as
tokenIdparameter;16015286601757825753which is the CCIP Chain Selector of Ethereum Sepolia blockchain, as thedestinationChainSelectorparameter;1which stands that we are paying for CCIP fees in LINK, as thepayFeesInparameter.
Create a new TypeScript file under the scripts folder and name it crossChainTransferFrom.ts
Call the function by running the following command:
Prepare:
Your EOA address, as the
fromparameter;The address of an EOA on other chain where you want to cross-transfer your NFT, can be your EOA address, as
toparameter;The ID of a xNFT you want to cross-transfer, as
tokenIdparameter;16015286601757825753which is the CCIP Chain Selector of Ethereum Sepolia blockchain, as thedestinationChainSelectorparameter;1which stands that we are paying for CCIP fees in LINK, as thepayFeesInparameter.
Run:
Under the "Deployed Contracts" section, you should find the XNFT.sol contract you previously deployed to Arbitrum Sepolia. Find the crossChainTransferFrom function and provide the following parameters:
Your EOA address, as the
fromparameter;The address of an EOA on other chain where you want to cross-transfer your NFT, can be your EOA address, as
toparameter;The ID of a xNFT you want to cross-transfer, as
tokenIdparameter;16015286601757825753which is the CCIP Chain Selector of Ethereum Sepolia blockchain, as thedestinationChainSelectorparameter;1which stands that we are paying for CCIP fees in LINK, as thepayFeesInparameter.
Hit the "Transact" orange button.
You can now monitor this cross-chain transfer on CCIP Explorer page.

Once cross-chain NFT arrives to Ethereum Sepolia, you can manually display it inside your Metamask wallet. Navigate to the "NFT" tab and hit the "Import NFT" button.

Then, fill in XNFT.sol smart contract address on Ethereum Sepolia and token ID you received (0).

Finally, your NFT will appear inside Metamask wallet.

Last updated

