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.
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
const getStatusCCIP = async (messageId, destinationProtocol) => {
const data = await sdk.chainlink.getStatusCCIP({
protocol,
messageId,
destinationProtocol
})
return data
}
Now, deploy your contract on the desired source and destination networks. In our example, we will use the Ethereum Sepolia and Avalanche Fuji networks.
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.
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.
await sdk.chainlink.sendMessageCCIP({
protocol,
destinationProtocol,
wallet,
tokenAddress: '0xFd57b4ddBf88a4e07fF4e34C487b99af2Fe82a05', //
amount: '0.1',
payLink: true, // If true, we indicate that we want to pay the gas fee with LINK.
contractAddress: senderContractAddress, // Origin contract address.
to: receiveContractAddress // Destination contract address.
})
/* Example Response:
TransactionResponse {
hash: '0x500f9948df4dacd92e71bde7b99934661fe5776f4a6289aba84a423c15a932a4'
}
*/
Data
Sending data across blockchains.
await sdk.chainlink.sendMessageCCIP({
protocol,
destinationProtocol,
wallet,
text: "Cryptum Sdk",
payLink: true, // If true, we indicate that we want to pay the gas fee with LINK.
contractAddress: senderContractAddress, // Origin contract address.
to: receiveContractAddress // Destination contract address.
})
/* Example Response:
TransactionResponse {
hash: '0x500f9948df4dacd92e71bde7b99934661fe5776f4a6289aba84a423c15a932a4'
}
*/
Token with Data
Sending tokens with data across blockchains.
await sdk.chainlink.sendMessageCCIP({
protocol,
destinationProtocol,
wallet,
tokenAddress: '0xFd57b4ddBf88a4e07fF4e34C487b99af2Fe82a05',
amount: '0.1',
text: "Cryptum Sdk",
payLink: true, // If true, we indicate that we want to pay the gas fee with LINK.
contractAddress: senderContractAddress, // Origin contract address.
to: receiveContractAddress // Destination contract address.
})
/* Example Response:
TransactionResponse {
hash: '0x500f9948df4dacd92e71bde7b99934661fe5776f4a6289aba84a423c15a932a4'
}
*/
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.
await sdk.chainlink.withdrawCCIP({
protocol,
wallet,
contractAddress:address,
to: wallet.address,
tokenAddress
})
/* Example Response:
TransactionResponse {
hash: '0x500f9948df4dacd92e71bde7b99934661fe5776f4a6289aba84a423c15a932a4'
}
*/