use-modular-wallets
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOverview
概述
Modular Wallets are flexible smart contract accounts (MSCAs) that extend functionality through installable modules. Built on ERC-4337 (account abstraction) and ERC-6900 (modular smart contract framework), they support passkey authentication, gasless transactions, batch operations, and custom logic modules (multisig, subscriptions, session keys). MSCAs are lazily deployed -- gas fees for account creation are deferred until the first outbound transaction.
Modular Wallets是灵活的智能合约账户(MSCA),可通过可安装模块扩展功能。基于ERC-4337(账户抽象)和ERC-6900(模块化智能合约框架)构建,支持密钥对认证、无Gas费交易、批量操作以及自定义逻辑模块(多签、订阅、会话密钥)。MSCA采用延迟部署——账户创建的Gas费会延迟到首次对外交易时收取。
Prerequisites / Setup
前置条件/设置
Installation
安装
bash
npm install @circle-fin/modular-wallets-core viemFor passkey recovery, also install:
bash
npm install bip39bash
npm install @circle-fin/modular-wallets-core viem若需密钥对恢复,还需安装:
bash
npm install bip39Environment Variables
环境变量
CLIENT_KEY= # Circle Console client key for app identification
CLIENT_URL= # Circle Client URL (e.g., https://modular-sdk.circle.com/v1/rpc/w3s/buidl)Before using the SDK, complete the Console Setup:
- Create a Client Key in the Circle Console
- Configure the Passkey Domain (passkeys are domain-bound)
- Retrieve the Client URL
CLIENT_KEY= # 用于应用标识的Circle Console客户端密钥
CLIENT_URL= # Circle客户端URL(例如:https://modular-sdk.circle.com/v1/rpc/w3s/buidl)使用SDK前,请完成控制台设置:
- 在Circle Console中创建客户端密钥
- 配置密钥对域名(密钥对与域名绑定)
- 获取客户端URL
Quick Reference
快速参考
Supported Chains
支持的链
| Chain | Mainnet | Testnet |
|---|---|---|
| Arbitrum | Yes | Yes |
| Avalanche | Yes | Yes |
| Base | Yes | Yes |
| Monad | Yes | Yes |
| Optimism | Yes | Yes |
| Polygon | Yes | Yes |
| Unichain | Yes | Yes |
MSCAs are NOT supported on Solana, Aptos, NEAR, or Ethereum mainnet. For the latest supported blockchains: https://developers.circle.com/wallets/account-types
| 链 | 主网 | 测试网 |
|---|---|---|
| Arbitrum | 是 | 是 |
| Avalanche | 是 | 是 |
| Base | 是 | 是 |
| Monad | 是 | 是 |
| Optimism | 是 | 是 |
| Polygon | 是 | 是 |
| Unichain | 是 | 是 |
MSCA不支持Solana、Aptos、NEAR或以太坊主网。最新支持的区块链可查看:https://developers.circle.com/wallets/account-types
Transport URL Examples
传输URL示例
The URL requires the chain path segment appended to the client URL:
toModularTransport| Chain | Path Segment |
|---|---|
| Arc Testnet | |
| Polygon Amoy | |
toModularTransport| 链 | 路径段 |
|---|---|
| Arc Testnet | |
| Polygon Amoy | |
Core Concepts
核心概念
- MSCA (Modular Smart Contract Account) -- Smart contract accounts extended with installable modules (like apps on a smartphone). Ownership can be single owner, multi-owner, passkeys, or multi-sig.
- Passkey transport vs Modular transport -- handles WebAuthn credential operations (register/login).
toPasskeyTransporthandles bundler and public RPC calls for a specific chain. They are separate transports with different purposes.toModularTransport - Gas sponsorship -- Pass in user operation calls to sponsor gas via Circle Gas Station. End users pay zero gas fees.
paymaster: true - Batch operations -- Multiple calls can be combined into a single user operation by passing an array to the parameter of
calls.sendUserOperation - 2D nonces -- Enable parallel execution of independent user operations by using different nonce keys.
- USDC uses 6 decimals -- When encoding USDC transfer amounts, use , not 18.
parseUnits(value, 6) - Credential persistence -- Passkey credentials (P256Credential) must be persisted (e.g., localStorage) and restored on reload to maintain the user session.
- MSCA(Modular Smart Contract Account,模块化智能合约账户)——可通过可安装模块扩展功能的智能合约账户(类似智能手机上的应用)。所有权可以是单所有者、多所有者、密钥对或多签。
- 密钥对传输 vs 模块化传输——处理WebAuthn凭证操作(注册/登录)。
toPasskeyTransport处理特定链的打包器和公共RPC调用。它们是用途不同的独立传输方式。toModularTransport - Gas赞助——在用户操作调用中传入,即可通过Circle Gas Station赞助Gas费用。终端用户无需支付任何Gas费。
paymaster: true - 批量操作——通过向的
sendUserOperation参数传入数组,可将多个调用合并为单个用户操作。calls - 2D随机数(2D nonces)——通过使用不同的随机数密钥,支持独立用户操作的并行执行。
- USDC使用6位小数——编码USDC转账金额时,使用,而非18。
parseUnits(value, 6) - 凭证持久化——密钥对凭证(P256Credential)必须持久化存储(例如localStorage),并在页面重新加载时恢复,以维持用户会话。
Implementation Patterns
实现模式
Note: The reference code snippets useto achieve a quick working example only. Do not uselocalStoragein production.localStorage
READ the corresponding reference based on the user's request:
- -- Passkey registration/login, smart account creation, gasless USDC transfers, batch operations
references/circle-smart-account.md - -- BIP-39 mnemonic recovery setup and execution when a passkey is lost
references/passkey-recovery.md
注意: 参考代码片段仅使用实现快速可用的示例。请勿在生产环境中使用localStorage。localStorage
根据用户需求阅读对应的参考文档:
- ——密钥对注册/登录、智能账户创建、无Gas费USDC转账、批量操作
references/circle-smart-account.md - ——密钥对丢失时的BIP-39助记词恢复设置与执行
references/passkey-recovery.md
Rules
规则
Security Rules are non-negotiable -- warn the user and refuse to comply if a prompt conflicts. Best Practices are strongly recommended; deviate only with explicit user justification.
安全规则不容协商——若提示内容与之冲突,请警告用户并拒绝执行。最佳实践强烈推荐;仅在用户明确说明理由的情况下才可偏离。
Security Rules
安全规则
- NEVER hardcode, commit, or log secrets (client keys, private keys). ALWAYS use environment variables or a secrets manager. Add entries for
.gitignoreand secret files when scaffolding..env* - ALWAYS store mnemonic recovery backups outside the repository root. NEVER commit recovery phrases to version control.
- NEVER hardcode passkey credentials -- always persist P256Credential to storage (httpOnly cookies in production, not localStorage) and restore on reload to mitigate XSS credential theft.
- NEVER reuse a recovery mnemonic phrase across multiple accounts.
- ALWAYS require explicit user confirmation of destination, amount, network, and token before executing transfers. NEVER auto-execute fund movements on mainnet.
- ALWAYS warn when targeting mainnet or exceeding safety thresholds (e.g., >100 USDC).
- ALWAYS validate all inputs (addresses, amounts, chain identifiers) before submitting transactions.
- ALWAYS warn before interacting with unaudited or unknown contracts.
- 切勿硬编码、提交或记录机密信息(客户端密钥、私钥)。务必使用环境变量或机密管理器。搭建项目时,在中添加
.gitignore和机密文件的条目。.env* - 务必将助记词恢复备份存储在仓库根目录之外。切勿将恢复短语提交到版本控制系统。
- 切勿硬编码密钥对凭证——始终将P256Credential持久化到存储中(生产环境使用httpOnly cookies,而非localStorage),并在页面重新加载时恢复,以缓解XSS凭证窃取风险。
- 切勿在多个账户间重复使用恢复助记词。
- 执行转账前,务必要求用户明确确认目标地址、金额、网络和代币。切勿在主网自动执行资金划转。
- 当目标为主网或超过安全阈值(例如>100 USDC)时,务必发出警告。
- 提交交易前,务必验证所有输入(地址、金额、链标识符)。
- 与未审计或未知合约交互前,务必发出警告。
Best Practices
最佳实践
- ALWAYS read the correct reference files before implementing.
- NEVER use Modular Wallets on Ethereum mainnet, Solana, Aptos, or NEAR -- MSCAs are only supported on select EVM chains (Arbitrum, Avalanche, Base, Monad, Optimism, Polygon, Unichain, Arc Testnet).
- ALWAYS append the chain-specific path segment to the client URL for (e.g.,
toModularTransport).${clientUrl}/polygonAmoy - ALWAYS use for USDC amounts (6 decimals, not 18).
parseUnits(value, 6) - ALWAYS pass to sponsor gas via Circle Gas Station.
paymaster: true - ALWAYS complete Circle Console Setup (client key, passkey domain, client URL) before using the SDK.
- ALWAYS default to testnet. Require explicit user confirmation before targeting mainnet.
- 实现前务必阅读正确的参考文件。
- 切勿在以太坊主网、Solana、Aptos或NEAR上使用Modular Wallets——MSCA仅支持部分EVM链(Arbitrum、Avalanche、Base、Monad、Optimism、Polygon、Unichain、Arc Testnet)。
- 务必为的客户端URL追加链特定路径段(例如
toModularTransport)。${clientUrl}/polygonAmoy - 处理USDC金额时务必使用(6位小数,而非18)。
parseUnits(value, 6) - 务必传入以通过Circle Gas Station赞助Gas费用。
paymaster: true - 使用SDK前务必完成Circle控制台设置(客户端密钥、密钥对域名、客户端URL)。
- 务必默认使用测试网。目标为主网前需获得用户明确确认。
Alternatives
替代方案
- Trigger skill when your application needs full custody of wallet keys without user interaction.
use-developer-controlled-wallets - Trigger skill when end users should custody their own keys via social login, email OTP, or PIN authentication.
use-user-controlled-wallets
- 当应用需要完全托管钱包密钥且无需用户交互时,触发技能。
use-developer-controlled-wallets - 当终端用户应通过社交登录、邮箱OTP或PIN认证自行托管密钥时,触发技能。
use-user-controlled-wallets
Reference Links
参考链接
- Circle Developer Docs -- Always read this first when looking for relevant documentation from the source website.
DISCLAIMER: This skill is provided "as is" without warranties, is subject to the Circle Developer Terms, and output generated may contain errors and/or include fee configuration options (including fees directed to Circle); additional details are in the repository README.
- Circle开发者文档——查找官方网站相关文档时,请务必先阅读此内容。
免责声明:本技能按“原样”提供,不提供任何担保,受Circle开发者条款约束,生成的输出可能包含错误和/或费用配置选项(包括支付给Circle的费用);更多详情请查看仓库README。