@circle-fin/usdckit v0.17.1
USDCKit
Introduction
USDCKit is a Node.js SDK that streamlines interactions with USDC. With USDCKit, you can integrate USDC into your applications and enable secure and efficient blockchain transactions. USDCKit aims to provide multi-chain fund orchestration features to enable USDC payment use cases like crypto acquiring (C2B), payroll (B2C), remittance (C2C), and B2B cross-border payments. We currently support features for transferring tokens, retrieving wallet balances, and sweeping tokens.
The SDK is compatible with popular open-source clients like viem, web3.js, and ethers.js, and can also function as a standalone client. The SDK is built with TypeScript and supports high-level use cases involving USDC, making it an important tool for developers working with digital currencies.
This guide will help you get started quickly and efficiently, whether you're building a wallet, a payment gateway, or anything in between. It covers the following items:
- Benefits of using USDCKit
- Quickstart to write your first line of code using USDCKit
- Sample Code to run USDC Acquiring Flow
Benefits of Using USDCKit
- Faster time-to-market. USDCKit simplifies accepting and managing USDC payments with minimal code. It provides reusable payment modules and removes technical complexities for faster integration.
- Payment Focused. USDCKit is built to offer all the features and tools required to create a complete end-to-end USDC payment flow, with functionalities tailored for payment use cases. It also includes sample code for specific payment products, making it easier to develop your own. The focus of the current release is USDC Acquiring use case.
- Scalable payments without bottlenecks. Process millions of transactions efficiently with USDCKit’s high-performance infrastructure.
- Enterprise-grade compliance management. Adhere to global regulatory standards with real-time transaction screening through Compliance Engine.
Key features
USDCKit supports the following features:
- Wallet management: Create and manage wallets across multiple chains.
- Balance querying and filtering: Query wallet balances and filter wallets by balance threshold.
- Fund transfer: Transfer funds between wallets on the same chain.
- Cross-chain transfer: Transfer funds between wallets on different chains.
- Fund sweeping: Automate fund aggregation and optimize gas efficiency.
Quickstart Steps
Setup
USDCKit is built on top of Circle Wallets’ developer-controlled wallets. You will need to set up a Developer Console account before using the service. Please follow these steps: 1. Sign Up: Go to the Developer Console and sign up for an account. This account will be used to manage your access to Circle’s Developer Services. Follow the instructions for more details. 2. Generate API Keys: Navigate to the API section of your project and generate a new API key. Make sure to store the API key securely as it will be used to authenticate your requests. Follow the instructions for more details. 3. Generate Entity Secret: The Entity Secret is a robust 32-byte key engineered to enhance the security mechanisms of wallets. Follow the instructions to setup your Entity Secret. 4. You are good to go!
Installation
To install USDCKit from NPM, run the following command in your project directory:
npm install @circle-fin/usdckitInitialization
To get started with USDKit, initialize a client with the API Key and Entity Secret from Setup
import { createCircleClient } from '@circle-fin/usdckit'
import { ETH_SEPOLIA } from '@circle-fin/usdckit/chains'
const client = createCircleClient({
apiKey: 'REPLACE_WITH_CIRCLE_API_KEY',
entitySecret: 'REPLACE_WITH_CIRCLE_ENTITY_SECRET',
// Optional. Defaults to `ETH_SEPOLIA`
chain: ETH_SEPOLIA,
})Usage
Create Account
To create a new account, use the createAccount method. This will generate a new account that you can use for various operations such as transferring tokens and retrieving balances.
// Creates an account on the default chain ETH_SEPOLIA
const account = await client.createAccount()Query for accounts
To query for existing accounts, use the getAccounts method. This will return the account details associated with the provided account query.
// Query by Address
const account = await client.getAccounts({ address: '0xmy-address' })
// Query by refId
const account = await client.getAccounts({ refId: 'user-1' })
// Query by balance
const account = await client.getAccounts({ amountGte: 1000 })Fund Account with Testnet Tokens
To fund an account with testnet tokens, you can use the drip method. This method provides native tokens, USDC, and EURC for testing purposes.
// Receive native tokens, USDC, and EURC
await client.drip({ account })
// Receive native
await client.drip({ account, token: null })
// Receive USDC
await client.drip({ account, token: client.chain.contracts.USDC })Transfer tokens
The transfer method allows the transferring of native or ERC-20 tokens between accounts. Multiple source accounts can be transferred with a single call. Fees can be controllable using the fees parameter. Below are examples of how to use the transfer() method for each type of token.
// Create Transfer - Native Tokens
const transaction_native = await client.transfer({
from: account,
to: anotherAccount,
amount: '0.00000001', // or use base units `1n`
})
// Create Transfer - USDC
const transaction_usdc = await client.transfer({
from: account,
to: anotherAccount,
token: client.chain.contracts.USDC,
amount: '0.01',
})
// Create Transfer - Cross chain USDC
const transaction_usdc = await client.transfer({
from: accountOnETH_SEPOLIA,
to: accountOnMATIC_AMOY,
token: ETH_SEPOLIA.contracts.USDC,
amount: '0.01',
})Batch Transfers
Transfer from multiple source accounts to a single destination account
// Create Transfer - Batch transfer
const transaction_batch = await client.transfer({
from: [account_1, account_2],
to: account_3,
token: client.chain.contracts.USDC,
amount: '0.01',
})Drain specified tokens from account
drainFrom function transfers all specified tokens from one account to another. In this example, it transfers all USDC tokens from account_1 to account_2.
const transaction_drain = await client.drainFrom({
from: account_1,
to: account_2,
token: client.chain.contracts.USDC,
})Get Account Balance
Use getTokenBalances to retrieve the token balances for a specified account.
const balance = await client.getTokenBalances({ account: account_2 })Sample Code to run USDC Acquiring Flow
For more details on how to run an end-to-end USDC Acquiring Flow to support your business, refer to the USDC Acquiring Flow sample code
Future Plans
The current private release marks the first version of USDCKit, and we recognize that additional tools are needed to create a smooth USDC payment experience. As such, we are actively working on several modules and would greatly appreciate your feedback. Our roadmap includes, but is not limited to, the following:
- Swap of USDC
- Mass Payout of USDC
- Gas Efficiency Enhancement
Feedback & Support
If you have any questions or need assistance, don't hesitate to reach out to the team directly(usdckit@circle.com). We're here to support you every step of the way.
Happy coding!