We refreshed our doc site!
Bookmarked links may have changed
Read release notesWe refreshed our doc site!
Bookmarked links may have changed
Read release notesCircle's Cross-Chain Transfer Protocol (CCTP) facilitates the transfer of USDC between distinct blockchains, providing a more streamlined experience. By integrating CCTP with programmable wallets in your applications, you enable seamless USDC transactions across multiple chains. This reduces the need for users to manage separate wallets for different blockchains, potentially broadening your audience and providing increased liquidity and adaptability. It's designed to provide users with a cohesive and efficient digital currency experience.
Leverage Blockchain-Specific Attributes
Use blockchain-specific characteristics to optimize your user experience. For instance, by bridging your ETH from Ethereum Mainnet to an Ethereum Layer 2 rollup, such as Polygon, you gain access to lower transaction fees while still enjoying the benefits of USDC.
Cross-Chain Swaps
Enable cross-chain swaps, allowing users to exchange digital assets that reside on different chains. For example, users can swap AVAX for USDC on Avalanche, route it to Polygon Mainnet, and further swap it for MATIC token, expanding liquidity across multiple chains.
Cross-Chain Purchases
Facilitate cross-chain purchases with minimal effort. Users can utilize USDC on Avalanche to buy an NFT on Uniswap on Ethereum, then list it for sale on OpenSea. CCTP effortlessly routes the USDC from Avalanche to Ethereum for the purchase.
Solve Fragmented Liquidity
Remove liquidity fragmentation barriers. If a user needs to send USDC to an address on Avalanche but only holds USDC on Ethereum, the solution becomes seamless. By bridging the USDC from Ethereum to Avalanche through CCTP, users can transact across different blockchains.
By the conclusion of this interactive guide, you will learn how to facilitate a transfer of USDC across blockchains using a Programmable Wallet. Specifically, the guide will demonstrate a scenario wherein a user conducts a USDC transfer leveraging the Cross-Chain Transfer Protocol (CCTP). You will follow step-by-step instructions to create and execute a USDC transfer from Sepolia, an Ethereum testnet, to Mumbai, the Polygon Testnet, via a programmable wallet. This practical walkthrough is designed to equip you with the knowledge to implement CCTP in your own applications.
Completing a Cross-Blockchain Transfer: Step-By-Step Process
To utilize CCTP effectively, it's necessary to authorize the USDC contract to conduct transfers on a user's behalf. In this guide, we approve only a small amount of USDC for demonstration. However, for operational efficiency, you might want to approve a larger amount to minimize the frequency of this action in a production environment.
Following the user's request to move USDC from Ethereum to Polygon, leverage the provided tools to initiate burning the specified amount of USDC from the Ethereum wallet created for this transaction.
Circle monitors the burn event on the Ethereum blockchain and issues an attestation. Retrieve this attestation using the relevant procedures, which serves as the authorization required to mint the corresponding USDC amount on the Polygon blockchain.
Utilize the retrieved attestation to start the minting process. The attestation confirms the amount of USDC to mint on the Polygon blockchain, and the amount to allocate to the specified Polygon wallet.
Smart contracts are computer protocols that automate the execution of agreements, operating under a set of predefined conditions. Once deployed onto a blockchain, they follow an "if-then" logic to perform actions automatically when specific conditions are met. The immutable nature of blockchain ensures that the smart contract code cannot be changed once established, which reinforces their reliability as they will always execute exactly as programmed. A smart contract typically consists of code that defines its operations, a data storage area, memory, and a unique public address that can be interacted with through its functions. For a comprehensive exploration of smart contracts, you are encouraged to read further on the dedicated resource.
The Cross-Chain Transfer Protocol (CCTP) serves as an integral tool within the blockchain infrastructure to guarantee the secure and seamless transfer of USDC across various blockchain networks. By adopting CCTP, users can benefit from a protected and efficient means of transferring USDC between supported chains, which currently include Ethereum, Arbitrum, Optimism, and Avalanche. Ongoing developments suggest plans to expand support to additional networks. To learn more about CCTP, see Cross-Chain Transfer Protocol in the Circle Developer Documentation.
To get started, Create a Circle Web3 Services account in the console.
Before you get started, ensure that you have:
In the process of transferring USDC from Ethereum to Polygon, you need to give the TokenMessenger contract the necessary permissions to execute the USDC transfer on your behalf. In essence, you're empowering the TokenMessenger contract to access and transfer the specified amount of USDC from your source wallet.
For this, we use the Programmable Wallets contract execution API:
Term | Definition |
---|---|
contractAddress | You interact with the USDC contract on the source chain, so the |
abiFunctionSignature | The function called on the USDC contract is approve(address spender, uint256 value). Calling approve allows the value is denominated in the smallest unit of USDC, which is a millionth of a dollar. In this case it's |
abiParameters | In this case, In this case it's |
walletId | The wallet that performs the contract execution. This is the ID of the developer-controlled wallet you created earlier. |
feeLevel | A dynamic blockchain fee level setting (LOW, MEDIUM, or HIGH) that will be used to pay gas for the transaction. HIGH is used for this transaction. |
idempotencyKey | Universally unique identifier (UUID v4) idempotency key. This is automatically generated for you. |
entitySecretCiphertext | A base64 string expression of the entity secret ciphertext. Refer to this helpful tool. |
The second step of the process facilitates a burn of the specified amount of USDC on Ethereum Sepolia (the source chain) that you are looking to move to Polygon Mumbai (the destination chain).
Mint and Burn are the terms used to refer to the creation and removal of a token from a blockchain network. During the CCTP transfer, tokens on one blockchain are burnt, removing them from the total supply, before new tokens are minted on the destination blockchain - effectively moving USDC across chains.
To do this, you again use Programmable Wallets contract execution API:
Term | Definition |
---|---|
contractAddress | You interact with the Token Messenger contract on the source chain, so the |
abiFunctionSignature | The function being called on the TokenMessenger contract is: This will be the abiFunctionSignature property of the request. In this case it's depositForBurn(uint256,uint32,bytes32,address) |
abiParameters | The abiParameters property defines the values to pass to the function. For the call to depositForBurn, they are amount, destinationDomain, mintRecipient and burnToken.
JavaScript
Therefore, the complete abiParameters value is [1000000, 7, {encodedDestinationAddress}, “0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238”]. |
walletId | The wallet that is performing the contract execution. This will be the ID of the developer-controlled wallet you created earlier. |
feeLevel | A dynamic blockchain fee level setting (LOW, MEDIUM, or HIGH) that will be used to pay gas for the transaction. HIGH is used for this transaction. |
idempotencyKey | Universally unique identifier (UUID v4) idempotency key. This is automatically generated for you. |
entitySecretCiphertext | A base64 string expression of the entity secret ciphertext. Refer to this helpful tool. |
Just like your first contract execution request, the other parameters - walletId
, feeLevel
, idempotencyKey
, and EntitySecretCiphertext
- were automatically populated in the request.
After initiating the burn of USDC through our API, you can check whether it was successful in our Developer Console.
To begin the process of validating your burn of USDC, log in to the Web3 Services Console.
Within the console, locate the Wallets page under Dev Controlled Wallet. This page displays all of the wallets you created thus far. Open the Wallets page.
Find and click on the Ethereum Sepolia wallet from which you initiated the USDC burn.
On the wallet details screen, scroll down to the bottom to find the section displaying your wallet balances. As you successfully created your Sepolia Wallet, an initial deposit of 10 USDC was made. If you have successfully burned 1 USDC, the total wallet balance should now reflect 9 USDC, indicating the accurate deduction of the burned amount.
By following these step-by-step instructions and reviewing your wallet balance in the Web3 Services Console, you can confidently validate the burn of your USDC tokens and verify the correct adjustment in your wallet's overall balance.
As a result of interacting with the TokenMessenger contract, Circle generates a unique ID for the transaction. Starting with the returned transaction ID, you call Circle's Attestation service to fetch an attestation that the burn took place. This attestation proves that the USDC was removed from circulation on the source chain.
The transactionId returned is a unique transaction ID generated by Circle. It is distinct from the unique identifier that is used to track the transaction on the blockchain - known as the transaction hash.
The attestation is used on the destination chain to mint new USDC. You can make API calls to get the transaction's transactionHash
, retrieve the logs of the depositForBurn
transaction, and use Circle's Attestation API to fetch the attestation signature. The steps have been broken down for you here, but you can use the following "Try It Out" component to run all of these steps together.
Call the Programmable Wallets API to fetch the transaction object for the depositForBurn
transaction. Make a GET request using the provided code and the transaction ID. Retrieve the transaction object from the response data.
Using a Web3 library like web3 or ethers, decode and create messageBytes
and messageHash
from the transaction object's txHash
. Follow the provided code snippet to extract the relevant information.
// get messageBytes from EVM logs using txHash of the transaction.
const transactionReceipt = await web3.eth.getTransactionReceipt(
transaction.txHash,
)
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)
Retrieve the attestation signature from Circle's Iris API using the messageHash
obtained in the previous step. Use the provided code inside a loop to query the API until the attestation status is "complete". Access the attestation signature from the response.
// Get attestation signature from iris-api.circle.com
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))
}
The attestation service is rate-limited. Please limit your requests to less than 10 per second.
Message hash refers to the cryptographic value that represents the specific
message related to the USDC burn transaction. It serves as a fingerprint of
the transaction and helps ensure its integrity and authenticity. The message
hash plays a crucial role in verifying and validating the burn transaction on
the source blockchain, allowing participants to track and confirm the
successful burning of tokens. As a developer, you will need to generate the
message hash using the Keccak-256 hash of the bytes emitted by the
MessageSent
event, as shown previously.
To mint USDC on the destination blockchain, we're using the messageBytes
from the depositForBurn
event and the attestation signature (attestationResponse.attestation
). We're fetching both from Circle's attestation services and calling the receiveMessage
function on the Message Transmitter contract in the destination blockchain network.
Using the Programmable Wallets smart contract execution API:
Term | Definition |
---|---|
contractAddress | You interact with the Message Transmitter contract on the destination chain, so the |
abiFunctionSignature | The function being called on the Message Transmitter contract is: This is the |
abiParameters | For the call to receiveMessage, the abiParameters are
|
walletId | The wallet that is performing the contract execution. This will be the ID of the developer-controlled wallet you created earlier. |
feeLevel | A dynamic blockchain fee level setting (LOW, MEDIUM, or HIGH) that will be used to pay gas for the transaction. HIGH is used for this transaction. |
idempotencyKey | Universally unique identifier (UUID v4) idempotency key. This is automatically generated for you. |
entitySecretCiphertext | A base64 string expression of the entity secret ciphertext. Refer to this helpful tool. |
Once the message has been received, the specified amount of USDC is minted at the recipient's address on the destination blockchain.
This returns a transactionId
after you submit the receiveMessage
request. You can use this transactionId
to look up the status and details of the final transaction.
Throughout this process, you've successfully:
Set up a Developer-Controlled Wallet
You successfully established a developer-controlled wallet using the Programmable Wallet system. This wallet gives you full control and flexibility over your users' wallets, ensuring a secure and frictionless experience.
Interacted with USDC and CCTP Contracts
Using your newly created wallet, you seamlessly interacted with the USDC and CCTP contracts. This enabled you to initiate and monitor USDC transfers, ensuring transparency and control over the process.
Completed USDC Mint on Mumbai
To finalize the USDC minting process on the Mumbai testnet, you called Circle's attestation service. This step ensures the successful creation and verification of USDC tokens on Matic.
Your journey with us doesn't stop here. There's so much more to discover und dive into:
Engage, Build, Share! Dive into our forums, share your feedback, and keep an eye out for exciting challenges and hackathons. Your unique perspective and skills are valuable, and we're eager to see the innovations you'll introduce to our growing ecosystem.
Before you embark further on your journey, we'd love to hear from you. Your feedback shapes the future of our platform and helps us provide a better experience for all developers.
What did you love about the process? Was there something you wish was different? Every insight, no matter how small, matters to us.
Thank you for your trust, dedication, and enthusiasm. Here's to the next chapter in your web3 journey and the marvelous innovations you'll bring forth.
Happy Building! 🚀
Next: Explore more Quickstarts