The Connect SDK enables fast, cheap, native USDC bridging powered by Circle's Cross Chain Transfer Protocol. Using CCTP to transfer native USDC across chains with the Connect SDK works very much like a standard Token Transfer with the SDK.
Installation
First install the SDK package
npminstall@wormhole-foundation/sdk
Usage
To use the CCTP bridge, the platform must be imported and registered
Wait for the Circle Attestation to be available, optionally passing a
// See https://developers.circle.com/stablecoins/docs/required-block-confirmations for reasonable timeout settings// based on origin chainconsttimeout=60*1000;console.log("Waiting for Attestation");constattestIds=awaitxfer.fetchAttestation(timeout);console.log(`Got Attestation: `, attestIds);
Complete the transfer by calling, you guessed it, completeTransfer and again passing a Signer for the destination chain
Using the Automatic Relaying feature is even easier and only involves initiating the transfer. The Relayer infrastructure will handle fetching and delivering the Attestation for you.
constxfer=awaitwh.circleTransfer( amount, srcAddress, dstAddress,true,// automatic transfer plzundefined,// An arbitrary bytes payload if one is necessary0n,// no native gas dropoff for this demo );console.log(xfer);console.log("Starting Transfer");constsrcTxids=awaitxfer.initiateTransfer(src.signer);console.log(`Started Transfer: `, srcTxids);
Complete Partial Transfer
In the case that a manual transfer is started but not finished, the transfer object can be reconstituted from only the source chain and transaction hash.
This is especially useful in cases where a user has terminated their session prior to completing the transfer or even for debugging.
consttimeout=60*1000// Rebuild the transfer from the source txidconstxfer=awaitCircleTransfer.from(wh, { chain:"Avalanche", txid:"0x6b6d5f101a32aa6d2f7bf0bf14d72bfbf76a640e1b2fdbbeeac5b82069cda4dd", }, timeout);constdstTxIds=awaitxfer.completeTransfer(signer);console.log("Completed transfer: ", dstTxIds);
The full source of a working example is available here