CCTP Quickstart Guide

Overview

Cross-Chain Transfer Protocol (CCTP) uses generalized message passing to facilitate the native burning and minting of USDC across supported blockchains, also known as domains. Message passing is a three-step process:

  1. An on-chain component on source domain emits a message.
  2. Circle's off-chain attestation service signs the message.
  3. The on-chain component at the destination domain receives the message, and forwards the message body to the specified recipient.

Architecture

  • CCTP on EVM Domains
image.png

Usecase: Cross-chain USDC transfer

Tips: The next phrase is gasless, which will replace approval in fulture.

Transfer USDC on testnet from Ethereum to Avalanche,The script has 5 steps:

  1. In this first step, you initiate a transfer of USDC from one blockchain to another, and specify the recipient wallet address on the destination chain. This step approves the Ethereum Sepolia TokenMessenger contract to withdraw USDC from the provided Ethereum Sepolia wallet address.
const approveTx = await usdcEthContract.methods.approve(ETH_TOKEN_MESSENGER_CONTRACT_ADDRESS, amount).send({gas: approveTxGas})

  1. In this second step, you facilitate a burn of the specified amount of USDC on the source chain. This step executes depositForBurn function on the Ethereum Sepolia TokenMessenger contract deployed on Sepolia testnet.
const burnTx = await ethTokenMessengerContract.methods.depositForBurn(amount, AVAX_DESTINATION_DOMAIN, destinationAddressInBytes32, USDC_ETH_CONTRACT_ADDRESS).send();

  1. In this third step, you make sure you have the correct message and hash it. This step extracts messageBytes emitted by MessageSent event from depositForBurn transaction logs and hashes the retrieved messageBytes using the keccak256 hashing algorithm.
const transactionReceipt = await web3.eth.getTransactionReceipt(burnTx.transactionHash);
const eventTopic = web3.utils.keccak256('MessageSent(bytes)')
const log = transactionReceipt.logs.find((l) => l.topics[0] === eventTopic)
const messageBytes = web3.eth.abi.decodeParameters(['bytes'], log.data)[0]
const messageHash = web3.utils.keccak256(messageBytes);

#------------------------demo----------------------------------
txhash:https://sepolia.etherscan.io/tx/0xefb38f685cd9c462d5a8b239c3c3accd10120e01cf2b7da2eac8ad30eccadb9f#eventlog
message bytes:
0x0000000000000000000000060000000000040DBF0000000000000000000000009F3B8679C73C2FEF8B59B4F3444D4E156FB70AA50000000000000000000000009F3B8679C73C2FEF8B59B4F3444D4E156FB70AA50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001C7D4B196CB0C7B01D743FBC6116A902379C7238000000000000000000000000D920AF54662E86F329DA602873FD0DFE6D86982A0000000000000000000000000000000000000000000000000000000000E4E1C0000000000000000000000000D920AF54662E86F329DA602873FD0DFE6D86982A
messageHash :0xb0938b8b0fba8d3124214bf02dd429929b4f0b0ff88be552378dc176626d9dc2
  1. In this fourth step, you request the attestation from Circle, which provides authorization to mint the specified amount of USDC on the destination chain. This step polls the attestation service to acquire the signature using the messageHash from the previous step.
let attestationResponse = {status: 'pending'};
while(attestationResponse.status != 'complete') {
    const response = await fetch(`https://iris-api-sandbox.circle.com/attestations/${messageHash}`);
    attestationResponse = await response.json()
    await new Promise(r => setTimeout(r, 2000));
}

#------------------------demo----------------------------------
messageHash :0xb0938b8b0fba8d3124214bf02dd429929b4f0b0ff88be552378dc176626d9dc2
attestationResponse :
{
    "attestation": "0x7bd45bdb013047d224a6d62fc134236f0e38637760eb7b479c58d59ae8bd9af701e45c7a88cd9211e0c190caf41c7b031a62109b73c688dfacb98545a88d4bc71b2ed1c3ab35f598d46250ccbb1e69dcc72dbcf0e4365998feeedaf712cf52e0c277f8e2ff187cb96e0208de2976f4c3a91358e1b99be65df096cc1874da361feb1c",
    "status": "complete"
}
  1. In this final step, you enable USDC to be minted on the destination chain. This step calls the receiveMessage function on the Avalanche Fuji MessageTransmitter contract to receive USDC at the Avalanche Fuji wallet address.
const receiveTx = await avaxMessageTransmitterContract.receiveMessage(receivingMessageBytes, signature);

版权声明:
作者:dingding
链接:https://www.techfm.club/p/184297.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>