LogoLogo
  • Introduction
  • Quick Start
    • Developing Cross Chain Dapps
      • Standard Relayer
      • Specialized Relayer
    • Tutorials
      • Hello Wormhole
        • Hello Wormhole Explained
        • Beyond Hello Wormhole
      • Hello Token
      • CCTP
        • USDC Transfers With Connect SDK
      • Simple Relayer
        • Advanced Relayer Example
    • Demos
    • Wormhole Connect: Bridging Made Easy
  • Explore Wormhole
    • Architecture
    • Security
    • Core Contracts
    • Guardians
    • VAAs
    • Relayers
    • Spy
    • Gateway
      • Onboarding
  • Reference
    • Constants Reference
    • Development Environment
      • Tilt
      • Tooling
    • Blockchain Platforms
      • Algorand
      • Aptos
      • CosmWasm
      • EVM
        • Relayer
      • Near
      • Solana
      • Sui
    • API Docs
      • Wormholescan API
    • SDK Docs
      • Legacy SDK
    • CLI Docs
    • Glossary
  • Wormhole Connect
    • Overview
    • Routes
    • Features
    • Configuration
  • Native Token Transfers
    • Overview
      • System Components
      • Deployment Models
    • Deployment
      • Installation
      • Deploy to EVM
      • Deploy to Solana
      • Post Deployment
    • Configuration
      • Rate Limiting
      • Access Control
    • Security
    • Custom Transceivers
    • Architecture
      • EVM Message Lifecycle
      • Solana Message Lifecycle
  • Queries
    • Overview
    • Getting Started
    • FAQs
  • MultiGov
    • Overview
    • Getting Started
    • Deployment
      • Configuration
    • Upgrading
    • Architecture
    • Guides
    • FAQs
  • External Links
    • Explorer
    • Ecosystem
    • Guardian Dashboard
    • Portal Bridge Docs
    • Discord
    • Twitter
    • Github
Powered by GitBook
On this page
  • Installation
  • Usage
  • Manual Transfer
  • Automatic Transfer
  • Complete Partial Transfer

Was this helpful?

Edit on GitHub
  1. Quick Start
  2. Tutorials
  3. CCTP

USDC Transfers With Connect SDK

Last updated 1 year ago

Was this helpful?

The Connect SDK enables fast, cheap, native USDC bridging powered by Circle's Cross Chain Transfer Protocol. Using to transfer native USDC across chains with the works very much like a standard Token Transfer with the SDK.

Installation

First install the SDK package

npm install @wormhole-foundation/sdk

Usage

To use the CCTP bridge, the platform must be imported and registered

import { Wormhole } from "@wormhole-foundation/sdk";
import evm from "@wormhole-foundation/sdk/evm";

// ...

const wh = await wormhole("Testnet", [evm]);

Manual Transfer

  const srcAddress = Wormhole.chainAddress("Ethereum", "0xdeadbeef...") 
  const dstAddress = Wormhole.chainAddress("Avalanche", "0xbeefdead...") 

  const xfer = await wh.circleTransfer(
    1_000_000n, // 
    srcAddress,
    dstAddress
  );
  console.log(xfer);

A Manual transfer has 3 steps:

  console.log("Starting Transfer");
  const srcTxids = await xfer.initiateTransfer(src.signer);
  console.log(`Started Transfer: `, srcTxids);
  1. 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 chain
  const timeout = 60 * 1000;

  console.log("Waiting for Attestation");
  const attestIds = await xfer.fetchAttestation(timeout);
  console.log(`Got Attestation: `, attestIds);
  1. Complete the transfer by calling, you guessed it, completeTransfer and again passing a Signer for the destination chain

  console.log("Completing Transfer");
  const dstTxids = await xfer.completeTransfer(dst.signer);
  console.log(`Completed Transfer: `, dstTxids);

Automatic Transfer

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.

  const xfer = await wh.circleTransfer(
    amount,  
    srcAddress, 
    dstAddress,
    true,       // automatic transfer plz
    undefined,  // An arbitrary bytes payload if one is necessary
    0n,         // no native gas dropoff for this demo
  );
  console.log(xfer);

  console.log("Starting Transfer");
  const srcTxids = await xfer.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.

  const timeout = 60 * 1000

  // Rebuild the transfer from the source txid
  const xfer = await CircleTransfer.from(wh, {
    chain: "Avalanche",
    txid: "0x6b6d5f101a32aa6d2f7bf0bf14d72bfbf76a640e1b2fdbbeeac5b82069cda4dd",
  }, timeout);

  const dstTxIds = await xfer.completeTransfer(signer);
  console.log("Completed transfer: ", dstTxIds);

Initiate The transfer by calling initiateTransfer and passing a to sign the transactions.

The full source of a working example is available

CCTP
Connect SDK
here
Signer