Transfer Tokens with Data Using Chainlink CCIP

·

Cross-chain interoperability is a cornerstone of modern blockchain development, enabling seamless transfer of assets and data across disparate networks. Chainlink’s Cross-Chain Interoperability Protocol (CCIP) provides a secure, standardized way to move tokens and arbitrary data between blockchains. This guide walks you through using Chainlink CCIP to transfer both tokens and text data from Avalanche Fuji to Ethereum Sepolia, with support for paying transaction fees in either LINK or native gas tokens like AVAX.

Whether you're building decentralized applications (dApps), cross-chain bridges, or multi-chain DeFi protocols, mastering CCIP empowers your smart contracts to communicate securely and efficiently across ecosystems.


Prerequisites

Before diving into the implementation, ensure you meet the following requirements:

👉 Get started with cross-chain development tools and resources here.


How CCIP Enables Cross-Chain Transfers

Chainlink CCIP allows developers to send messages, transfer tokens, and execute logic across blockchains in a trust-minimized manner. The protocol abstracts complex routing, security, and execution layers, letting smart contracts focus on application logic.

In this tutorial, we’ll use a single contract that:

This dual-payment model gives developers flexibility: use LINK for predictable fee estimation or native tokens for user convenience.


Core Contract Functionality

The example contract ProgrammableTokenTransfers inherits from CCIPReceiver and OwnerIsCreator, ensuring secure message receipt and ownership control. It supports two primary functions:

  1. sendMessagePayLINK() – Pay CCIP fees in LINK.
  2. sendMessagePayNative() – Pay fees in native gas (AVAX).

Both functions trigger cross-chain messages containing:

Security is enforced via:


Step-by-Step Deployment Guide

1. Deploy the Sender Contract on Avalanche Fuji

  1. Open Remix IDE and load the contract code.
  2. Switch MetaMask to Avalanche Fuji Testnet.
  3. In Remix, select Injected Provider - MetaMask under Deploy & Run Transactions.
  4. Provide these parameters during deployment:

    • Router Address: 0xF694E193200268f9a4868e4Aa017A0118C9a8177
    • LINK Contract Address: 0x0b9d5D9136855f6FEc3c0993feE6E9CE8a297846
  5. Deploy the contract and note its address.

2. Fund and Configure the Sender Contract

  1. Transfer 0.002 CCIP-BnM and 70 LINK (for fee testing) to the deployed contract.
  2. In Remix, call allowlistDestinationChain() with:

    • _destinationChainSelector: 16015286601757825753 (Ethereum Sepolia)
    • allowed: true

This enables outbound messaging to Sepolia.

3. Deploy the Receiver Contract on Ethereum Sepolia

  1. Switch MetaMask to Ethereum Sepolia.
  2. Deploy the same contract again using:

    • Router Address: 0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59
    • LINK Contract Address: 0x779877A7B0D9E8603169DdbD7836e478b4624789
  3. Note the receiver contract address.

4. Secure the Receiver Contract

Call these functions in order:

These steps prevent unauthorized message delivery.


Transfer Tokens & Data Paying Fees in LINK

Use this method when you want predictable fee costs denominated in LINK.

Steps:

  1. Ensure your sender contract has sufficient LINK balance (≥70 LINK recommended).
  2. In Remix, call sendMessagePayLINK() with:

    • _destinationChainSelector: 16015286601757825753
    • _receiver: Your receiver contract address on Sepolia
    • _text: "Hello World!"
    • _token: 0xD21341536c5cF5EB1bcb58f6723cE26e8D8E90e4 (CCIP-BnM on Fuji)
    • _amount: 1000000000000000 (equals 0.001 tokens)
  3. Confirm the transaction in MetaMask.

Verification:

👉 Explore real-time cross-chain message tracking tools now.


Transfer Tokens & Data Paying Fees in Native Gas (AVAX)

This approach uses native AVAX for fees, simplifying user experience by avoiding dependency on LINK.

Steps:

  1. Fund your sender contract with at least 0.2 AVAX.
  2. Call sendMessagePayNative() with identical parameters as above.

Note: The key difference is _feeTokenAddress is set to address(0), signaling native gas usage.

  1. Confirm transaction and monitor via CCIP Explorer.

Even though fees are paid in AVAX, they are internally priced in LINK — node operators receive compensation in LINK regardless of payment method.


Frequently Asked Questions (FAQ)

Q: What is Chainlink CCIP?

A: Chainlink Cross-Chain Interoperability Protocol (CCIP) is an open standard enabling secure movement of data and tokens across blockchains. It powers cross-chain dApps, bridges, and asset transfers with built-in security and decentralization.

Q: Can I transfer multiple tokens in one message?

A: Yes! While this example sends one token, the tokenAmounts array supports multiple EVMTokenAmount entries, allowing batch transfers of different ERC20 tokens.

Q: Why do I need to allowlist chains and senders?

A: Allowlisting prevents unauthorized access and replay attacks. It ensures only trusted sources can send or receive messages, enhancing contract security.

Q: Are fees always denominated in LINK?

A: Yes — even when paying in native gas (like AVAX), the fee amount is calculated in LINK equivalents. This ensures consistent compensation for oracle operators.

Q: Can I receive messages back from Sepolia to Fuji?

A: Absolutely. The contract is bidirectional. After deploying both sides, you can initiate transfers in either direction by configuring the corresponding allowlists.

Q: Is this contract production-ready?

A: No — this is an educational example using hardcoded values and un-audited code. For production use, integrate dynamic configuration, error handling, and formal audits.


Key Code Components Explained

Building the CCIP Message

The _buildCCIPMessage() function constructs an EVM2AnyMessage struct containing:

Best practice: Compute extraArgs off-chain to adapt to network conditions and future upgrades.

Receiving Messages Securely

The _ccipReceive() function processes incoming messages only if:

Received data is stored in state variables and emitted via MessageReceived event for easy off-chain monitoring.


Final Thoughts

Mastering Chainlink CCIP unlocks powerful capabilities for building truly interoperable blockchain applications. By supporting both LINK and native gas fee payments, developers gain flexibility without sacrificing security.

As multi-chain ecosystems grow, tools like CCIP become essential infrastructure for DeFi, NFTs, gaming, and enterprise solutions.

👉 Start building cross-chain applications with advanced developer tools today.


Core Keywords: Chainlink CCIP, cross-chain token transfer, CCIP tutorial, pay CCIP fees in LINK, pay CCIP fees in native gas, programmable token transfer, blockchain interoperability, EVM cross-chain messaging