### Set Up Node.js Project and Install Dependencies Source: https://developers.circle.com/xreserve/tutorials/deposit-usdc-on-ethereum-for-usdcx-on-canton This snippet sets up a new Node.js project directory, initializes it with npm, and installs essential libraries like viem for blockchain interaction and dotenv for environment variable management. ```shell # Set up your directory and initialize the project mkdir deposit-usdc-into-xreserve-for-usdcx-on-canton-quickstart cd deposit-usdc-into-xreserve-for-usdcx-on-canton-quickstart npm init -y # Install tools and dependencies npm install viem dotenv ``` -------------------------------- ### Install Modular Wallets Web SDK using npm Source: https://developers.circle.com/wallets/modular/create-a-wallet-and-send-gasless-txn This command installs the core SDK for modular wallets on the web. Ensure you have Node.js and npm (or yarn) installed. ```bash npm install @circle-fin/modular-wallets-core ``` -------------------------------- ### Install Aptos SDK and Wallet Adapters Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-aptos Installs the necessary Aptos SDK and wallet adapter packages required for interacting with the Aptos blockchain and managing user wallets within the application. ```shell npm install @aptos-labs/ts-sdk @aptos-labs/wallet-adapter-ant-design @aptos-labs/wallet-adapter-react ``` -------------------------------- ### Install Viem and Dotenv Dependencies Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-sei Installs the necessary JavaScript libraries for interacting with blockchains (Viem) and managing environment variables (dotenv). ```shell npm install viem dotenv ``` -------------------------------- ### Initialize Project and Install Dependencies (Shell) Source: https://developers.circle.com/stablecoins/quickstart-transfer-10-usdc-on-chain Commands to create a new project directory, initialize an npm project, and install essential React, Vite, and TypeScript dependencies for building a React app. ```shell mkdir usdc-transfer-app cd usdc-transfer-app npm init -y npm install react@^18.2.0 \ react-dom@^18.2.0 \ @types/react@^18.0.27 \ @types/react-dom@^18.0.10 \ @vitejs/plugin-react@^3.1.0 \ typescript@^5.0.3 \ vite@^4.4.5 ``` -------------------------------- ### Install Dependencies for Sui Integration Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-sui Installs essential libraries for interacting with the Sui blockchain and managing wallet connections within a React application. These include SDKs for Sui, wallet integration, and query management. ```shell npm install @mysten/dapp-kit @mysten/sui @mysten/wallet-kit @tanstack/react-query ``` -------------------------------- ### Install Dependencies with npm Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-ink Initializes a new Node.js project, sets the module type to ES module, and installs the necessary Viem and dotenv libraries. These are fundamental for interacting with blockchain and managing environment variables. ```shell npm init -y npm pkg set type=module npm install viem dotenv ``` -------------------------------- ### Install Viem Library Source: https://developers.circle.com/stablecoins/quickstart-transfer-10-eurc-on-chain Installs the viem library, a lightweight, fast, and type-safe Ethereum utilities library for TypeScript and JavaScript. It's crucial for interacting with the Ethereum blockchain. ```shell npm install viem ``` -------------------------------- ### Install Circle Contracts Python SDK Source: https://developers.circle.com/sdks/contracts-python-sdk Installs the Circle Smart Contract Platform SDK using pip. Ensure you have Python installed and an active Circle Developer Account. ```bash pip install circle-smart-contract-platform ``` -------------------------------- ### Set up Development Environment with npm Source: https://developers.circle.com/gateway/quickstarts/unified-balance Initializes a new Node.js project, sets the package type to module, and installs necessary dependencies like viem and dotenv. This is the first step in setting up the project environment. ```shell mkdir unified-balance-quickstart && cd unified-balance-quickstart npm init -y npm pkg set type="module" npm install --save viem dotenv ``` -------------------------------- ### Main Application Component Setup Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-aptos This component serves as the main entry point for the application, wrapping the core UI logic (`HomeContent`) with necessary providers. It ensures that state management and wallet connection functionalities are available throughout the application tree. The component includes basic error handling for the provider. ```typescript export default function Home() { return ( ); } ``` -------------------------------- ### Install User-Controlled Wallets Python SDK Source: https://developers.circle.com/sdks/user-controlled-wallets-python-sdk Installs the Circle User-Controlled Wallets Python SDK using pip. Ensure you have Python installed and are using a virtual environment for best practices. ```bash pip install circle-user-controlled-wallets ``` -------------------------------- ### Testing Authentication Source: https://developers.circle.com/circle-mint/authentication Verify your API key setup by using the 'get configuration info' API endpoint. This example uses cURL to make a GET request to the sandbox configuration endpoint. ```APIDOC ## GET /v1/configuration ### Description Tests the authentication by retrieving configuration information. This is a good way to verify if your API key is correctly set up. ### Method GET ### Endpoint `https://api-sandbox.circle.com/v1/configuration` ### Parameters #### Headers - **Accept** (string) - Required - `application/json` - **Authorization** (string) - Required - `Bearer YOUR_API_KEY` ### Request Example ```bash # Replace ${YOUR_API_KEY} with your API key curl -H 'Accept: application/json' \ -H "Authorization: Bearer ${YOUR_API_KEY}" \ -X GET --url https://api-sandbox.circle.com/v1/configuration ``` ### Response #### Success Response (200) - **data** (object) - Contains configuration details. - **payments** (object) - **masterWalletId** (string) - The master wallet ID. #### Response Example ```json { "data": { "payments": { "masterWalletId": "1234567890" } } } ``` #### Error Response (401) - **code** (integer) - The error code. - **message** (string) - A description of the error. #### Response Example ```json { "code": 401, "message": "Malformed authorization. Are the credentials properly encoded?" } ``` ``` -------------------------------- ### Install Node.js SDK for Developer-Controlled Wallets Source: https://developers.circle.com/sdks/developer-controlled-wallets-nodejs-sdk Install the developer-controlled wallets SDK using npm or yarn. This command adds the necessary package to your project for interacting with Circle's wallet APIs. Ensure you have Node.js and npm installed. ```bash npm install @circle-fin/developer-controlled-wallets --save ``` ```bash yarn add @circle-fin/developer-controlled-wallets ``` -------------------------------- ### Initialize Project with npm Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-sei Initializes a new project directory and sets up npm for module usage. It creates a package.json file and configures it to use ES modules. ```shell mkdir usdc-sei-script cd usdc-sei-script npm init -y npm pkg set type=module ``` -------------------------------- ### Example SNS Notification Response Source: https://developers.circle.com/circle-mint/circle-apis-notifications-quickstart This example shows the plain text format of a response received from Amazon Simple Notification Service (SNS) when subscribing to Circle notifications. It includes essential details for verifying the subscription and signing the request. ```plaintext { "Type": "SubscriptionConfirmation", "MessageId": "43f97f6e1865505e2f29f79a62f89e18f97e03a0dd5d982a7578c8d6e21154163f2d6aae523cff25557f9bc21b2503d413006", "Timestamp": "2020-04-11T20:50:16.324Z", "SignatureVersion": "1", "Signature": "kBr9z/ysQrr0ldowHY4lThkOA+dwyjcsyx7NwkbTkgEKG4N61BSSEA+43aYQEB/Ml09hclybvyjyRKWYOjaxQgbUXWmyWrCQ7vY93WYhuGvOqZxAMPiDiILxLs6/KtOxneKVvzfpK4abLrYyTTA+z/dQ52h9L8eoiSKSW81e4clfYBTJkGmuAPKFC08FvEAVT89VikPp68mBf4CctPv3Em0b4J1VvDhAB21B2LekgUmwUE0aE7fUbsF3XsKGQd/fDshLOJasQEuXSqdB5X7LITBA8r24FY+wCjwm8oR3VI9IMy21fUC6wMgoFIVZHW1KxzpEkMCSe7R1ySdNIru8SQ==", "SigningCertURL": "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem" } ``` -------------------------------- ### Project Setup with Next.js Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-sui Initializes a new Next.js project with TypeScript, ESLint, and Tailwind CSS. This command sets up the basic structure for the web application. ```shell npx create-next-app@latest usdc-transfer-app ``` -------------------------------- ### Test API Key Authentication using curl Source: https://developers.circle.com/w3s/keys This `curl` command example shows how to test your API key setup by making a GET request to retrieve wallets from the Circle API. It includes the necessary headers for authentication and specifies the endpoint. ```shell curl --request GET \ --url https://api.circle.com/v1/w3s/wallets \ --header 'accept: application/json' \ --header 'authorization: Bearer ' ``` -------------------------------- ### List Developer-Controlled Wallets - cURL Request Source: https://developers.circle.com/wallets/dev-controlled/receive-an-inbound-transfer This example shows how to list developer-controlled wallets using a cURL command. It demonstrates the HTTP GET request to the appropriate API endpoint. The response includes a list of wallets with their details, such as address and state. ```bash curl "https://api.circle.com/v1/wallets" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" ``` -------------------------------- ### Navigate to Project Directory Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-aptos Change the current directory to the newly created Next.js project directory to begin installing dependencies and modifying files. ```shell cd usdc-transfer-app ``` -------------------------------- ### Get USDC Transfer Fees Response Example (JSON) Source: https://developers.circle.com/api-reference/cctp/all/get-burn-usdc-fees Example JSON response for the 'Get USDC Transfer Fees' API call, detailing `finalityThreshold` and `minimumFee` in basis points for different transfer types. ```json [ { "finalityThreshold": 1000, "minimumFee": 1 }, { "finalityThreshold": 2000, "minimumFee": 0 } ] ``` -------------------------------- ### Set up Wallet Client (Viem) Source: https://developers.circle.com/stablecoins/quickstart-transfer-10-eurc-on-chain Configures a wallet client using viem to interact with user accounts and sign transactions. This example specifically sets it up to connect with MetaMask in the browser. ```typescript import { createWalletClient, custom } from "viem"; import { sepolia } from "viem/chains"; const walletClient = createWalletClient({ chain: sepolia, transport: custom(window.ethereum!), }); ``` -------------------------------- ### Challenge Initialization Notification Example Source: https://developers.circle.com/wallets/webhook-notifications This is an example of a notification message received when a challenge payment is initiated. ```APIDOC ## Sample Challenge Notification This JSON object represents a notification received upon successful initiation of a challenge payment. ```json { "subscriptionId": "a68cd974-d209-46cd-8dbf-b7a081fbd627", "notificationId": "eaa4a4fe-24b8-4329-a4c6-6dfd557dbcb2", "notificationType": "challenges.initialize", "notification": { "id": "9c0a1991-735a-5140-8996-7b95720c5e55", "userId": "2a054cd1-3124-4aa7-b1f0-86c4a4df995c", "type": "INITIALIZE", "status": "COMPLETE", "correlationIds": ["01890792-a199-77bc-b005-b229f81824fa"], "errorCode": 0, "errorMessage": "" }, "timestamp": "2023-06-29T14:33:17.785131449Z", "version": 2 } ``` ``` -------------------------------- ### Webhook Signature Verification Example (Python) Source: https://developers.circle.com/wallets/webhook-notifications Example code demonstrating how to verify the `X-Circle-Signature` header using the retrieved public key and the webhook payload. ```APIDOC ## Verify Digital Signature ### Description This section details how to verify the digital signature of incoming webhook notifications to ensure their integrity and authenticity. It involves retrieving the public key using the `X-Circle-Key-Id` header and then using it to validate the `X-Circle-Signature` against the payload. ### Headers - **X-Circle-Signature** (string) - The digital signature of the webhook payload. - **X-Circle-Key-Id** (string) - The UUID of the public key used for signing. ### Request 1. Use the `X-Circle-Key-Id` from the request headers to call the `GET /v2/notifications/publicKey/{keyId}` endpoint to retrieve the public key and algorithm. 2. Use the retrieved public key and algorithm to verify the `X-Circle-Signature` against the webhook payload. ### Request Example (Python) ```python import base64 from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import ec # Assume public_key_base64 and signature_base64 are obtained from previous steps # Assume message is the raw webhook payload string # --- Obtain Public Key (example, should be cached) --- public_key_base64 = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAESl76SZPBJemW0mJNN4KTvYkLT8bOT4UGhFhzNk3fJqf6iuPlLQLq533FelXwczJbjg2U1PHTvQTK7qOQnDL2Tg==" public_key_bytes = base64.b64decode(public_key_base64) public_key = serialization.load_der_public_key(public_key_bytes) # --- Obtain Signature and Message --- # Example values, replace with actual received data signature_base64 = "MEQCIBlJPX7t0FDOcozsRK6qIQwik5Fq6mhAtCSSgIB/yQO7AiB9U5lVpdufKvPhk3cz4TH2f5MP7ArnmPRBmhPztpsIFQ==" signature_bytes = base64.b64decode(signature_base64) message = "{\"subscriptionId\":\"00000000-0000-0000-0000-000000000000\",\"notificationId\":\"00000000-0000-0000-0000-000000000000\",\"notificationType\":\"webhooks.test\",\"notification\":{\"hello\":\"world\"},\"timestamp\":\"2024-01-26T18:22:19.779834211Z\",\"version\":2}" message_bytes = message.encode(encoding="utf-8") # --- Verify Signature --- try: public_key.verify( signature_bytes, message_bytes, ec.ECDSA(hashes.SHA256()), ) print("Signature is valid.") except InvalidSignature: print("Signature is invalid.") ``` ``` -------------------------------- ### Start Development Server Command Source: https://developers.circle.com/stablecoins/quickstart-setup-transfer-usdc-aptos This command initiates the development server for the project. It's typically executed from the project's root directory using a package manager like npm or yarn. The server allows for live reloading and efficient development workflows. ```shell npm run dev ``` -------------------------------- ### Get a Recipient - Circle API Response Example Source: https://developers.circle.com/api-reference/circle-mint/payouts/get-address-book-recipient This is an example JSON response for successfully retrieving a recipient's information from the Circle Crypto Address Book API. It includes details such as the recipient's ID, blockchain, address, metadata (nickname, email, bns), status, and timestamps. ```json { "data": { "id": "b8627ae8-732b-4d25-b947-1df8f4007a29", "chain": "ALGO", "address": "0x8381470ED67C3802402dbbFa0058E8871F017A6F", "addressTag": "123456789", "metadata": { "nickname": "sample nickname", "email": "satoshi@circle.com", "bns": "sample.circle" }, "status": "pending", "createDate": "2020-04-10T02:13:30.000Z", "updateDate": "2020-04-10T02:13:30.000Z" } } ``` -------------------------------- ### Get Event Monitors Response Example (JSON) Source: https://developers.circle.com/api-reference/contracts/smart-contract-platform/get-event-monitors Example JSON response for the 'Get Event Monitors' API endpoint. It contains a 'data' object with an 'eventMonitors' array, where each element represents a configured event monitor including its ID, blockchain, contract address, event signature, and status. ```json { "data": { "eventMonitors": [ { "id": "e3c998a5-bdf1-4f3e-812f-24da238c0fff", "blockchain": "ETH", "contractAddress": "0x6bc50ff08414717f000431558c0b585332c2a53d", "eventSignature": "Transfer(address indexed from, address indexed to, uint256 value)", "eventSignatureHash": "0xd3d3dd4b1fd3e53f94deb24e763485b4c925345c5abfa9ad529c67aa55a3b784", "isEnabled": true, "createDate": "2023-01-01T12:00:00Z", "updateDate": "2023-01-10T15:30:00Z" } ] } } ``` -------------------------------- ### Initialize Viem Clients and Contracts (JavaScript) Source: https://developers.circle.com/gateway/quickstarts/unified-balance Sets up Viem clients and contract instances for interacting with the Gateway protocol on different testnets. It requires a PRIVATE_KEY in the environment variables for account creation and uses specific RPC URLs for Base Sepolia. ```javascript import "dotenv/config"; import { createPublicClient, getContract, http, erc20Abi } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import * as chains from "viem/chains"; import { GatewayClient } from "./gateway-client.js"; import { gatewayWalletAbi, gatewayMinterAbi } from "./abis.js"; // Addresses that are needed across networks const gatewayWalletAddress = "0x0077777d7EBA4688BDeF3E311b846F25870A19B9"; const gatewayMinterAddress = "0x0022222ABE238Cc2C7Bb1f21003F0a260052475B"; const usdcAddresses = { sepolia: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", baseSepolia: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", avalancheFuji: "0x5425890298aed601595a70ab815c96711a31bc65", }; // Sets up a client and contracts for the given chain and account function setup(chainName, account) { const chain = chains[chainName]; const client = createPublicClient({ chain, account, // Use the flashblocks-aware RPC for Base Sepolia, otherwise use the default RPC transport: chainName === "baseSepolia" ? http("https://sepolia-preconf.base.org") : http(), }); return { client, name: chain.name, domain: GatewayClient.DOMAINS[chainName], currency: chain.nativeCurrency.symbol, usdc: getContract({ address: usdcAddresses[chainName], abi: erc20Abi, client, }), gatewayWallet: getContract({ address: gatewayWalletAddress, abi: gatewayWalletAbi, client, }), gatewayMinter: getContract({ address: gatewayMinterAddress, abi: gatewayMinterAbi, client, }), }; } // Create an account from the private key set in .env export const account = privateKeyToAccount(process.env.PRIVATE_KEY); console.log(`Using account: ${account.address}`); // Set up clients and contracts for each chain export const ethereum = setup("sepolia", account); export const base = setup("baseSepolia", account); export const avalanche = setup("avalancheFuji", account); ``` -------------------------------- ### Create and Initialize Project Directory (Shell) Source: https://developers.circle.com/stablecoins/quickstart-setup-usdc-trustline-xrpl This command creates a new directory for the XRPL USDC trustline project and initializes it with npm. This is the first step in setting up the project environment. ```shell mkdir xrpl-usdc-trustline cd xrpl-usdc-trustline npm init -y ``` -------------------------------- ### CCTP V2 Get Messages and Attestations Response Example (JSON) Source: https://developers.circle.com/api-reference/cctp/all/get-messages-v2 An example JSON response for the 'Get messages and attestations' API endpoint. It details a completed transaction with message hash, event nonce, attestation signature, and decoded message parameters including sender, recipient, and message body. The `decodedMessageBody` further breaks down the transfer details. ```json { "messages": [ { "message": "0x00000000000000050000000300000000000194c2a65fc943419a5ad590042fd67c9791fd015acf53a54cc823edb8ff81b9ed722e00000000000000000000000019330d10d9cc8751218eaf51e8885d058642e08a000000000000000000000000fc05ad74c6fe2e7046e091d6ad4f660d2a15976200000000c6fa7af3bedbad3a3d65f36aabc97431b1bbe4c2d2f6e0e47ca60203452f5d610000000000000000000000002d475f4746419c83be23056309a8e2ac33b30e3b0000000000000000000000000000000000000000000000000000000002b67df0feae5e08f5e6bf04d8c1de7dada9235c56996f4420b14371d6c6f3ddd2f2da78", "eventNonce": "9682", "attestation": "0x6edd90f4a0ad0212fd9fbbd5058a25aa8ee10ce77e4fc143567bbe73fb6e164f384a3e14d350c8a4fc50b781177297e03c16b304e8d7656391df0f59a75a271f1b", "decodedMessage": { "sourceDomain": "7", "destinationDomain": "5", "nonce": "569", "sender": "0xca9142d0b9804ef5e239d3bc1c7aa0d1c74e7350", "recipient": "0xb7317b4EFEa194a22bEB42506065D3772C2E95EF", "destinationCaller": "0xf2Edb1Ad445C6abb1260049AcDDCA9E84D7D8aaA", "messageBody": "0x00000000000000050000000300000000000194c2a65fc943419a5ad590042fd67c9791fd015acf53a54cc823edb8ff81b9ed722e00000000000000000000000019330d10d9cc8751218eaf51e8885d058642e08a000000000000000000000000fc05ad74c6fe2e7046e091d6ad4f660d2a15976200000000c6fa7af3bedbad3a3d65f36aabc97431b1bbe4c2d2f6e0e47ca60203452f5d610000000000000000000000002d475f4746419c83be23056309a8e2ac33b30e3b0000000000000000000000000000000000000000000000000000000002b67df0feae5e08f5e6bf04d8c1de7dada9235c56996f4420b14371d6c6f3ddd2f2da78", "decodedMessageBody": { "burnToken": "0x4Bc078D75390C0f5CCc3e7f59Ae2159557C5eb85", "mintRecipient": "0xb7317b4EFEa194a22bEB42506065D3772C2E95EF", "amount": "5000", "messageSender": "0xca9142d0b9804ef5e239d3bc1c7aa0d1c74e7350" } }, "cctpVersion": 2, "status": "complete" } ] } ``` -------------------------------- ### Initialize Project and Install Dependencies (Shell) Source: https://developers.circle.com/paymaster/pay-gas-fees-usdc Sets up a new Node.js project, configures it for ES modules, and installs necessary dependencies: viem for blockchain interaction and dotenv for environment variable management. ```shell npm init npm pkg set type="module" npm install --save viem dotenv ``` -------------------------------- ### Set up Wallet Client with viem (TypeScript) Source: https://developers.circle.com/stablecoins/quickstart-transfer-10-usdc-on-chain Configures a wallet client using viem to interact with Ethereum accounts for sending transactions and signing messages on the Sepolia network. ```typescript import { createWalletClient } from "viem"; import { sepolia } from "viem/chains"; const walletClient = createWalletClient({ chain: sepolia, transport: custom(window.ethereum!), }); ```