πŸ›€οΈCCIP

CCIP

Chainlink CCIP provides a single simple interface through which dApps and web3 entrepreneurs can securely meet all their cross-chain needs. You can use CCIP to transfer data, tokens, or both data and tokens across chains.

Read more about Chainlink CCIP

Before you begin

Before you begin, you need to ensure that you have a sufficient LINK.

Instantiate Cryptum SDK first:

const sdk = new CryptumSdk({
  environment: 'testnet',
  apiKey: 'YOUR-API-KEY'
})

Transfer Tokens between EOAs

In this example, you will transfer CCIP-BnM tokens from your EOA on Arbitrum to an account on Avalanche Fuji. The destination account could be an EOA (Externally Owned Account) or a smart contract.

const getWallet = async () => await sdk.wallet.generateWallet({
    protocol,
    mnemonic: process.env.MNEMONIC
})

const wallet = await getWallet();

await sdk.chainlink.sendTokenCCIPEoa({
    protocol: "ARBITRUM",
    wallet,
    to: "0x91438...6623", // destination wallet
    amount: '1',
    tokenAddress: 'CCIP-BnM', 
    destinationProtocol: "AVAXCCHAIN",
    // feeTokenAddress: '0x' // 0x for native token or token address or null for LINK token
})

/* Response:
TransactionResponse {
  hash: '0x082a35d8172700ec2c97538034d774feb44ec5d4e81b45116c4c368fc3bb79cc'
}
*/

Get Status By Message ID

Get Status By Transaction Hash

OnChain

Deploy Contract

Retrieve your wallet using the following command:

For more information about wallets, see: Wallet

Now, deploy your contract on the desired source and destination networks. In our example, we will use the Ethereum Sepolia and Avalanche Fuji networks.

Get Contract Address By Hash

Use the getTransactionReceiptByHash function to obtain the newly generated contract address.

Add Founds

You need to add funds to the generated contracts. Add ETH, LINK, and CCIP-BnM to your wallet.

You can obtain faucets through the link: https://docs.chain.link/ccip/test-tokens

CCIP-BnM: https://docs.chain.link/ccip/test-tokens

Note: The CCIP-BnM token is what we will send across networks, so it can be added only to the source contract. The other tokens should be added to all contracts.

For the contract on the Ethereum network, add ETH and LINK; for the contract created on the Avalanche Fuji network, add AVAX and LINK; and so on for the other networks.

This is necessary to ensure we have sufficient funds for gas payments.

Get Last Received Message

Retrieving the last received message.

Get Last send Message

Retrieving the last sent message.

Get Received Messages Id

Retrieving the list of received message IDs.

Get Sended Messages Id

Retrieving the list of sent message IDs.

Allow Listed Senders

To receive messages sent from another contract, we need to authorize the origin contract address on the destination contract.

In the allowlistedSendersCCIP function, we check whether the specified origin contract is authorized to send messages to the destination contract.

Allow Sender

In the allowSenderCCIP function, we can authorize or revoke authorization for the specified contract.

Send Message

Using the sendMessageCCIP function, you can send tokens, tokens with data, and just data across different networks.

Note: Follow all the previous steps carefully to ensure there are sufficient funds for gas payments on both the source and destination networks.

Token

Sending tokens across blockchains.

Data

Sending data across blockchains.

Token with Data

Sending tokens with data across blockchains.

After sending, if everything goes well, you will receive a hash. With this hash, you can check the status of the operation using the sdk.chainlink.getStatusCCIPByHash function or by visiting: https://ccip.chain.link.

Withdraw

To withdraw the tokens contained in your contract, use the withdrawCCIP function.

Last updated