@circle-fin/provider-gateway-v1

中文文档
1.7.1发布于 2026/11/06TypeScriptESM + CJS近 30 天下载 3.3万

Circle's Gateway v1 provider for instant cross-chain USDC transfers with unified balance management

原始使用文档
文档目录17 节
  1. Table of Contents
  2. Overview
  3. Why Gateway v1 Provider?
  4. Installation
  5. Quick Start
  6. Option 1: With Unified Balance Kit (Recommended)
  7. Option 2: Direct Provider Usage
  8. Features
  9. Supported Chains
  10. Usage Examples
  11. Basic Operations
  12. Balance Queries
  13. Error Handling
  14. Spend Process
  15. Integration with Unified Balance Kit
  16. Development
  17. License

Gateway v1 Provider

npm version TypeScript License Discord

Circle's Gateway v1 provider for Unified Balance Kit

Instant cross-chain USDC transfers with unified balance management across chains.

Table of Contents

Overview

The Gateway v1 Provider is a strongly-typed implementation of Circle's Gateway protocol that enables instant cross-chain USDC transfers with unified balance management across supported blockchain networks.

While primarily designed to power the Unified Balance Kit, this provider can also be used directly in applications that need fine-grained control over Gateway operations or want to integrate Gateway without the full Stablecoin Kits framework.

Why Gateway v1 Provider?

  • ⚡ Instant cross-chain moves: Pull from multiple source chains and mint on destination in one flow
  • 🌐 Unified balance model: Deposit once, spend anywhere—no waiting for finality between chains
  • 🔒 Circle's official protocol: Uses Circle's Gateway infrastructure for security and reliability
  • 🔧 Type-safe operations: Built with TypeScript strict mode and comprehensive validation
  • 🛠️ Direct integration: Use standalone or with custom orchestration logic

Installation

npm install @circle-fin/provider-gateway-v1
# or
yarn add @circle-fin/provider-gateway-v1

Note: This provider is included by default with the Unified Balance Kit. You can import this provider if you need to do a custom Gateway integration.

Quick Start

import {
  createUnifiedBalanceKitContext,
  deposit,
  spend,
  getBalances,
} from '@circle-fin/unified-balance-kit'

// Provider included by default
const context = createUnifiedBalanceKitContext()

const result = await deposit(context, {
  from: { adapter, chain: 'Ethereum' },
  amount: '100',
})

const spendResult = await spend(context, {
  amount: '50',
  from: { adapter, allocations: { amount: '50', chain: 'Ethereum' } },
  to: { adapter, chain: 'Base' },
})

const balances = await getBalances(context, { sources: { adapter } })

Option 2: Direct Provider Usage

import { createGatewayV1Provider } from '@circle-fin/provider-gateway-v1'

const provider = createGatewayV1Provider()

// Get supported chains
const chains = provider.getSupportedChains()

// Deposit USDC on a chain
await provider.deposit({
  from: { adapter, chain: 'Ethereum' },
  amount: '100',
  token: 'USDC',
})

// Estimate spend fees
const estimate = await provider.estimateSpend({
  from: {
    adapter,
    allocations: { amount: '100', chain: 'Ethereum' },
  },
  to: { adapter, chain: 'Base' },
  token: 'USDC',
})

// Execute spend (mint on destination)
const result = await provider.spend({
  from: {
    adapter,
    allocations: { amount: '100', chain: 'Ethereum' },
  },
  to: { adapter, chain: 'Base' },
  token: 'USDC',
})

// Query balances
const balances = await provider.getBalances({
  token: 'USDC',
  sources: { adapter, chains: ['Ethereum', 'Base'] },
})

Features

  • ✅ Deposits - Deposit USDC into Gateway accounts on any supported chain
  • ✅ Spends (mints) - Pull from one or more chains and mint on destination
  • ✅ Balance queries - Aggregated and per-chain USDC balances
  • ✅ Delegation - Add/remove delegates for Gateway accounts
  • ✅ Fund removal - Initiate and complete withdrawals from Gateway
  • ✅ Multi-source spends - Allocate amounts from multiple chains in one operation
  • ✅ Type safety - Full TypeScript support with structured KitError handling

Supported Chains

The provider supports all chains with Gateway v1 configuration. Call getSupportedChains() for the full list. Mainnet examples include Ethereum, Arbitrum, Base, Solana; testnet examples include Ethereum Sepolia, Base Sepolia, Solana Devnet.

import { createGatewayV1Provider } from '@circle-fin/provider-gateway-v1'

const provider = createGatewayV1Provider()
const chains = provider.getSupportedChains()
console.log(chains.map((c) => c.name))

Usage Examples

Basic Operations

const provider = createGatewayV1Provider()

// Deposit
await provider.deposit({
  from: { adapter, chain: 'Ethereum' },
  amount: '100',
  token: 'USDC',
})

// Spend (single source)
const result = await provider.spend({
  from: { adapter, allocations: { amount: '50', chain: 'Ethereum' } },
  to: { adapter, chain: 'Base' },
  token: 'USDC',
})
console.log(result.txHash, result.explorerUrl)

// Spend (multi-source)
const multiResult = await provider.spend({
  from: {
    adapter,
    allocations: [
      { amount: '30', chain: 'Ethereum' },
      { amount: '20', chain: 'Base' },
    ],
  },
  to: { adapter, chain: 'Avalanche' },
  token: 'USDC',
})

Balance Queries

const provider = createGatewayV1Provider()

// By adapter
const balances = await provider.getBalances({
  token: 'USDC',
  sources: { adapter, chains: ['Ethereum', 'Base'] },
})

// By account address (read-only)
const balancesByAddress = await provider.getBalances({
  token: 'USDC',
  sources: { address: '0x...', chains: ['Ethereum', 'Base'] },
})

// Include pending deposits
const withPending = await provider.getBalances({
  token: 'USDC',
  sources: { adapter },
  includePending: true,
})

Error Handling

The provider throws structured KitError instances for validation and execution failures:

import { createGatewayV1Provider } from '@circle-fin/provider-gateway-v1'
import { isKitError } from '@circle-fin/unified-balance-kit'

const provider = createGatewayV1Provider()

try {
  const result = await provider.spend(params)
  console.log('Success:', result.txHash)
} catch (error) {
  if (isKitError(error)) {
    console.error(`Error ${error.code}: ${error.name}`, error.message)
    if (error.recoverability === 'RESUMABLE' && error.cause?.trace) {
      const { attestation, signature, missingTokenAccounts } = error.cause
        .trace as {
        attestation: string
        signature: string
        missingTokenAccounts?: { tokenAccount: string; mint: string }[]
      }
      if (missingTokenAccounts?.length) {
        // Solana only: create the listed token accounts first, then retry
        // with the same attestation. Retrying now fails the same way.
        throw error
      }
      // Mint failed after transfer—retry with config.retry
      await provider.spend({
        ...params,
        config: { retry: { attestation, signature } },
      })
    }
  }
  throw error
}

Spend Process

The Gateway v1 provider handles the complete spend (mint) flow:

  1. Estimate - Fetch fee estimate from Gateway API
  2. Sign - Build and sign burn intents for each source chain
  3. Fetch Attestation - Submit signed intents to Gateway API, receive attestation
  4. Mint - Execute mint transaction on destination chain using attestation

When the mint step fails after the attestation is fetched (funds locked), the provider throws a KitError with recoverability: 'RESUMABLE' and attestation/signature in cause.trace. Use config.retry to reattempt the mint without re-running the fetch.

On Solana, the mint does not create recipient token accounts. Both errors below list the missing accounts in cause.trace.missingTokenAccounts. If the missing account belongs to the Circle fee recipient, contact Circle support instead.

  • Before the transfer (non-forwarder spends and estimateSpend): the provider checks the recipient token accounts before requesting an attestation. A missing account throws a VALIDATION_FAILED KitError that is FATAL. Nothing was submitted; create the accounts, then call spend again.
  • At mint time (for example on config.retry): a missing account throws a VALIDATION_FAILED KitError that is RESUMABLE. Create the accounts, then retry with config.retry. Retrying before they exist fails with the same error.

Integration with Unified Balance Kit

This provider is designed specifically for the Unified Balance Kit:

import { UnifiedBalanceKit } from '@circle-fin/unified-balance-kit'
import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'

const kit = new UnifiedBalanceKit()
const adapter = createViemAdapterFromPrivateKey({
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
})

// Monitor gateway events
kit.on('*', (event) => console.log('Event:', event))
kit.on('gateway.deposit.succeeded', (payload) =>
  console.log('Deposit:', payload.data),
)
kit.on('gateway.spend.succeeded', (payload) =>
  console.log('Spend succeeded:', payload.data.txHash),
)

// Execute operations
await kit.deposit({ from: { adapter, chain: 'Ethereum' }, amount: '100' })
const result = await kit.spend({
  amount: '50',
  from: { adapter, allocations: { amount: '50', chain: 'Ethereum' } },
  to: { adapter, chain: 'Base' },
})

Development

This package is part of the Stablecoin Kits monorepo.

# Build
nx build @circle-fin/provider-gateway-v1

# Test
nx test @circle-fin/provider-gateway-v1

License

This project is licensed under the Apache 2.0 License. Contact support for details.


Ready for cross-chain USDC operations?

Join Discord • Visit our Help-Desk

Built with ❤️ by Circle

版本与发布记录

@circle-fin/provider-gateway-v1 共发布 23 个版本,首次发布于 2026/04/22;过去 12 个月发布了 23 个版本。

版本发布日期距今
1.7.1latest2026/11/063 天前
1.7.02026/10/3110 天前
1.6.02026/10/2317 天前
1.5.32026/10/2119 天前
1.5.22026/10/1624 天前
1.5.12026/09/301 个月前

关于 @circle-fin/provider-gateway-v1 的常见问题

@circle-fin/provider-gateway-v1 是什么?

Circle's Gateway v1 provider for instant cross-chain USDC transfers with unified balance management

如何安装 @circle-fin/provider-gateway-v1?

在项目目录运行 npm install @circle-fin/provider-gateway-v1,或使用 pnpm add / yarn add / bun add。

@circle-fin/provider-gateway-v1 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@circle-fin/provider-gateway-v1 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@circle-fin/provider-gateway-v1 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@circle-fin/provider-gateway-v1 可以商用吗?

@circle-fin/provider-gateway-v1 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@circle-fin/provider-gateway-v1 的下载量有多少?

根据 npm 官方下载统计,@circle-fin/provider-gateway-v1 在 2026/10/10 – 2026/11/08 这 30 天内被下载 33,415 次,日均约 1,114 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@circle-fin/provider-gateway-v1 还在维护吗?

最新版本 1.7.1 发布于 2026/11/06(3 天前);至今共发布 23 个版本,其中过去 12 个月发布了 23 个;首次发布于 2026/04/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。