Circle Modular Wallets SDK(モジュール型暗号資産ウォレットのツール)を使用して、パスキー認証(生体認証や端末固有の認証)、手数料無料トランザクション(ガス代を払わずに処理を実行)、拡張可能なモジュール構造に対応したウォレットを構築します。 **次のような場合に使用:** - パスキーベース(WebAuthn/ウェブ標準の認証技術)での登録とログインでウォレットを作成する - Circle Gas Station(手数料負担サービス)のペイマスター機能を使ってガス代無料のトランザクションを送信する - 複数のトランザクションをひとつのユーザー操作にまとめて実行する - BIP-39ニーモニックフレーズ(バックアップ用の復旧フレーズ)を使ったパスキー復旧を実装する - マルチシグ(複数署名)、サブスクリプション、セッションキー(一時的なアクセス権限)などのカスタムモジュールで高度なオンチェーン(ブロックチェーン上の)ウォレットを構築する **トリガー対応:** MSCA、パスキー認証、WebAuthn、ペイマスター、Gas Station、ERC-4337、ERC-6900、toCircleSmartAccount、toModularTransport、sendUserOperation、2D nonce、パスキー復旧、EIP-1193プロバイダー
Build crypto wallets using Circle Modular Wallets SDK with passkey authentication, gasless transactions, and extensible module architecture. Use when: creating crypto wallets with passkey-based (WebAuthn) registration and login, sending gasless transactions using Circle Gas Station paymaster, batching multiple transactions into a single user operation, implementing passkey recovery using BIP-39 mnemonic phrases, building advanced onchain wallets with custom modules (multisig, subscriptions, session keys). Triggers on: MSCA, passkey authentication, WebAuthn, paymaster, Gas Station, ERC-4337, ERC-6900, toCircleSmartAccount, toModularTransport, sendUserOperation, 2D nonce, passkey recovery, EIP-1193 provider.
Modular Wallets(モジュール型ウォレット)は、インストール可能なモジュール(スマートフォンのアプリのような拡張機能)によって機能を追加できる柔軟なスマートコントラクト口座です。ERC-4337(アカウント抽象化技術)と ERC-6900(モジュール型スマートコントラクト の枠組み)の上に構築されており、パスキー認証、ガス代なしの取引、一括操作、カスタムロジック(マルチシグ・購読・セッション鍵)に対応しています。スマートコントラクト口座は遅延デプロイ(必要になるまで配置を延期)されるため、初回の送金時まで口座作成のガス代がかかりません。
npm install @circle-fin/modular-wallets-core viem
# パスキーリカバリーを使用する場合は bip39 も必要:
npm install bip39
Modular Wallets をセットアップする際に、プロジェクトの環境ファイルに以下を記述またはマージしてください:
# .env.local (Next.js) または .env (Vite)
# コンソール → キー → クライアント キーから取得したクライアントキーを貼り付けてください
# (1回だけ表示され、TEST_API_KEY: で始まります)
NEXT_PUBLIC_CLIENT_KEY=
NEXT_PUBLIC_CLIENT_URL=https://modular-sdk.circle.com/v1/rpc/w3s/buidl
VITE_CLIENT_KEY=
VITE_CLIENT_URL=https://modular-sdk.circle.com/v1/rpc/w3s/buidl
Next.js の場合は NEXT_PUBLIC_* ペア、Vite の場合は VITE_* ペアを使用してください。両方は使用しないでください。クライアント URL は固定値です。ユーザーに コンソールからコピーさせないでください。ブロックチェーンのチェーン識別子(/arcTestnet など)は、環境変数ではなく、コード内の toModularTransport で追加されます。
SDK を使用する前に、セットアップを完了してください(コンソールセットアップ を参照):
| ブロックチェーン | メインネット | テストネット |
|---|---|---|
| Arc | 対応 | 対応 |
| Arbitrum | 対応 | 対応 |
| Avalanche | 対応 | 対応 |
| Base | 対応 | 対応 |
| Monad | 対応 | 対応 |
| Optimism | 対応 | 対応 |
| Polygon | 対応 | 対応 |
| Unichain | 対応 | 対応 |
最新の対応ブロックチェーンについては、https://developers.circle.com/wallets/account-types.md を参照してください(MSCA(モジュール型スマートコントラクト口座)の制限事項は下記「ルール」を参照)。
toModularTransport URL にはクライアント URL に対してチェーンパス(ブロックチェーン識別子)を追加する必要があります:
| ブロックチェーン | メインネット パス | テストネット パス |
|---|---|---|
| Arbitrum | /arbitrum |
/arbitrumSepolia |
| Arc | /arc |
/arcTestnet |
| Avalanche | /avalanche |
/avalancheFuji |
| Base | /base |
/baseSepolia |
| Monad | /monad |
/monadTestnet |
| Optimism | /optimism |
/optimismSepolia |
| Polygon | /polygon |
/polygonAmoy |
| Unichain | /unichain |
/unichainSepolia |
例:Polygon Amoy テストネットの場合は toModularTransport(\${clientUrl}/polygonAmoy`, clientKey)` です。
MSCA(モジュール型スマートコントラクト口座) -- インストール可能なモジュールで拡張されたスマートコントラクト口座。スマートフォンにアプリを入れるような感覚で機能を追加できます。所有者は単一、複数所有者、パスキー、またはマルチシグ(複数署名)の何れかです。
パスキートランスポート vs モジュールトランスポート -- toPasskeyTransport は WebAuthn 認証情報の操作(登録・ログイン)を処理します。toModularTransport は特定のブロックチェーンのバンドラー(取引をまとめるサービス)とパブリック RPC(公開ノード)呼び出しを処理します。異なる目的の別々のトランスポートです。
ガス代スポンサーシップ -- ユーザー操作の呼び出しで paymaster: true を指定すると、Circle Gas Station(ガス代代行サービス)でガス代を負担できます。エンドユーザーはガス代を一切支払いません。
一括操作 -- sendUserOperation の calls パラメータに配列を渡すことで、複数の操作を 1 つのユーザー操作に組み合わせられます。
2D ノンス(2次元取引番号) -- 異なるノンス鍵を使用することで、独立したユーザー操作の並列実行が可能になります。
USDC は 6 桁小数 -- USDC 送金額をエンコードする場合、18 ではなく parseUnits(value, 6) を使用してください。
認証情報の永続化 -- パスキー認証情報(P256Credential)は永続化(本番環境では httpOnly クッキー)する必要があり、リロード時に復元してユーザーセッションを保つ必要があります。
注意: リファレンスコードスニペットは、動作例を素早く示すため
localStorageを使用しています。本番環境ではlocalStorageを使用しないでください。
ユーザーのリクエストに応じて、対応するリファレンスを読んでください:
references/circle-smart-account.md -- パスキー登録・ログイン、スマートアカウント作成、ガス代なしの USDC 送金、一括操作references/passkey-recovery.md -- BIP-39 ニーモニック(リカバリーフレーズ)のセットアップと、パスキーを紛失した場合の復旧実行sendUserOperation で送信されたユーザー操作は非同期ステートマシン(状態遷移図)に従います。SDK の waitForUserOperationReceipt は自動的にポーリング(定期確認)を処理します。状態を直接クエリするには、List User Operations API を使用してください。
正常系: SENT(送信) → CONFIRMED(確認済み) → COMPLETE(完了)
状態:
SENT -- バンドラーに送信され、ブロックへの含有を待機中。CONFIRMED -- ブロックに含有され、ブロックチェーンの確定を待機中。COMPLETE -- ブロックチェーンで確定。FAILED -- ユーザー操作が失敗、または回復不可能なエラーが発生。errorReason と revertReason を確認してください。FAILED 時のエラー理由:
FAILED_ON_CHAIN -- ブロックチェーン実行中にトランザクション処理が失敗。FAILED_REPLACED -- ユーザー操作が置き換えられた(例:同じ取引番号でガス代が高い操作)。| エラーコード | 意味 | 対応方法 |
|---|---|---|
NotAllowedError |
ユーザーがパスキープロンプトをキャンセルした、またはタイムアウト | ユーザーに再度プロンプトを出す。ログインの場合は、このドメイン用の認証情報が存在するか確認 |
SecurityError |
パスキードメインが不一致 -- 別のオリジンに紐付けられている | アプリのドメインが Circle コンソールのパスキードメイン設定と一致することを確認 |
InvalidStateError |
認証情報が既に登録済み(重複登録) | WebAuthnMode.Register の代わりに WebAuthnMode.Login に切り替える |
| 155203 | スマートコントラクトウォレットがまだデプロイされていないのに、ユーザー操作の取引番号が 0 を超えている | 最初のユーザー操作を取引番号 0 で送信してください。MSCA は初回取引時に遅延デプロイされます |
| 155505 | SCA ウォレット(スマートコントラクト口座)が初回の取引をキューイングされるのを待機中 | 初回デプロイメント取引が完了するまで待ってから、追加の操作を送信してください |
| 155507 | SCA アカウントが指定されたブロックチェーンでは非対応 | 対応チェーンを使用してください。MSCA は Ethereum メインネット、Solana、Aptos、NEAR では利用できません |
| 155509 | メインネットで SCA アカウント作成前に Gas Station ペイマスター(ガス代払い主)ポリシーが必須 | SCA アカウント作成前に Circle コンソールで Gas Station ペイマスターポリシーを設定してください |
| 155512 | SCA ウォレットの所有者が見つからない | パスキー認証情報または EOA(外部所有アカウント)所有者が有効でアクセス可能であることを確認 |
| AA21 | 送信者がプリファンド(事前資金)を支払っていない | paymaster: true が設定されていることを確認するか、スマートアカウントにネイティブトークン(Arc の場合は USDC)でガス代を充当してください |
| AA23 | アカウント検証が失敗または ガス不足 | 署名の有効性を確認。ガス不足の場合は verificationGasLimit を増やしてください |
| AA25 | アカウント取引番号が無効 | EntryPoint から現在の取引番号を取得。2D ノンスの場合は正しいノンス鍵を確認してください |
| AA33 | ペイマスター検証が失敗または ガス不足 | ペイマスターポリシーがアクティブで、コンソールで正しく設定されていることを確認 |
パスキーエラー(NotAllowedError、SecurityError、InvalidStateError)は、ブラウザの WebAuthn API が toWebAuthnCredential 実行時に発生させる標準的な DOMException エラーです。ウォレットエラー(155xxx)は Circle API から返されます。AA エラーは、バンドラーから返される ERC-4337 EntryPoint エラーです。詳細については、エラーコードを参照してください。失敗したトランザクションのデバッグについては、トランザクション状態とエラーを参照してください。
セキュリティルールは守らなければいけません。プロンプトがこれに違反する場合は、ユーザーに警告して実行を拒否してください。ベストプラクティスは強く推奨します。ユーザーから明確な理由がない限り、これから外れないでください。
.env* とシークレットファイルを .gitignore に追加してください。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.
npm install @circle-fin/modular-wallets-core viem
# Passkey recovery also needs bip39:
npm install bip39
Write or merge into the project's env file when scaffolding Modular Wallets:
# .env.local (Next.js) or .env (Vite)
# Paste your Client Key from Console → Keys → Client Keys (shown once; starts with TEST_API_KEY:)
NEXT_PUBLIC_CLIENT_KEY=
NEXT_PUBLIC_CLIENT_URL=https://modular-sdk.circle.com/v1/rpc/w3s/buidl
VITE_CLIENT_KEY=
VITE_CLIENT_URL=https://modular-sdk.circle.com/v1/rpc/w3s/buidl
Use the NEXT_PUBLIC_* pair for Next.js or the VITE_* pair for Vite — not both. Client URL is fixed — do not ask the user to copy it from Console. Chain paths (e.g. /arcTestnet) are appended in code via toModularTransport, not in the env var.
Before using the SDK, complete setup (see Console Setup):
| Chain | Mainnet | Testnet |
|---|---|---|
| Arc | Yes | Yes |
| Arbitrum | Yes | Yes |
| Avalanche | Yes | Yes |
| Base | Yes | Yes |
| Monad | Yes | Yes |
| Optimism | Yes | Yes |
| Polygon | Yes | Yes |
| Unichain | Yes | Yes |
For the latest supported blockchains: https://developers.circle.com/wallets/account-types.md (MSCA chain restrictions are in Rules below.)
The toModularTransport URL requires the chain path segment appended to the client URL:
| Chain | Mainnet Path | Testnet Path |
|---|---|---|
| Arbitrum | /arbitrum |
/arbitrumSepolia |
| Arc | /arc |
/arcTestnet |
| Avalanche | /avalanche |
/avalancheFuji |
| Base | /base |
/baseSepolia |
| Monad | /monad |
/monadTestnet |
| Optimism | /optimism |
/optimismSepolia |
| Polygon | /polygon |
/polygonAmoy |
| Unichain | /unichain |
/unichainSepolia |
Example: toModularTransport(\${clientUrl}/polygonAmoy`, clientKey)` for Polygon Amoy testnet.
toPasskeyTransport handles WebAuthn credential operations (register/login). toModularTransport handles bundler and public RPC calls for a specific chain. They are separate transports with different purposes.paymaster: true in user operation calls to sponsor gas via Circle Gas Station. End users pay zero gas fees.calls parameter of sendUserOperation.parseUnits(value, 6), not 18.Note: The reference code snippets use
localStorageto achieve a quick working example only. Do not uselocalStoragein production.
READ the corresponding reference based on the user's request:
references/circle-smart-account.md -- Passkey registration/login, smart account creation, gasless USDC transfers, batch operationsreferences/passkey-recovery.md -- BIP-39 mnemonic recovery setup and execution when a passkey is lostUser operations submitted via sendUserOperation follow an asynchronous state machine. The SDK's waitForUserOperationReceipt handles polling automatically. To query states directly, use the List User Operations API.
Happy path: SENT -> CONFIRMED -> COMPLETE
States:
SENT -- Submitted to the bundler, awaiting inclusion in a block.CONFIRMED -- Included in a block, awaiting finality.COMPLETE -- Finalized on-chain.FAILED -- User operation reverted or encountered an unrecoverable error. Check errorReason and revertReason.Error reasons on FAILED:
FAILED_ON_CHAIN -- Transaction reverted during blockchain execution.FAILED_REPLACED -- User operation was replaced (e.g., by a higher-fee operation with the same nonce).| Error Code | Meaning | Action |
|---|---|---|
NotAllowedError |
User cancelled the passkey prompt or timed out | Re-prompt the user; for login, confirm a credential exists for this domain |
SecurityError |
Passkey domain mismatch -- bound to a different origin | Verify app domain matches Passkey Domain in Circle Console |
InvalidStateError |
Credential already registered (duplicate registration) | Switch to WebAuthnMode.Login instead of Register |
| 155203 | User op nonce cannot be >0 when smart contract wallet hasn't been deployed | Send the first user operation with nonce 0; the MSCA deploys lazily on the first transaction |
| 155505 | SCA wallet needs to wait for first-time transaction to be queued | Wait for the initial deployment transaction to complete before sending additional operations |
| 155507 | SCA account not supported on the given blockchain | Use a supported chain; MSCAs are not available on Ethereum mainnet, Solana, Aptos, or NEAR |
| 155509 | Paymaster policy required on mainnet before SCA account creation | Configure a Gas Station paymaster policy in Circle Console before creating mainnet accounts |
| 155512 | Owner of the SCA wallet cannot be found | Verify the passkey credential or EOA owner is valid and accessible |
| AA21 | Sender didn't pay prefund | Verify paymaster: true is set, or fund the smart account with native tokens for gas (USDC on Arc) |
| AA23 | Account validation reverted or out of gas | Check signature validity; increase verificationGasLimit if out of gas |
| AA25 | Invalid account nonce | Get the current nonce from EntryPoint; ensure correct nonce key for 2D nonces |
| AA33 | Paymaster validation reverted or out of gas | Verify paymaster policy is active and correctly configured in Console |
Passkey errors (NotAllowedError, SecurityError, InvalidStateError) are standard DOMException errors thrown by the browser's WebAuthn API during toWebAuthnCredential. Wallet errors (155xxx) are returned by the Circle API. AA errors are ERC-4337 EntryPoint errors returned by the bundler. For the full error reference, see Error Codes. For debugging failed transactions, see Transaction States and Errors.
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.
.gitignore entries for .env* and secret files when scaffolding.toModularTransport (e.g., ${clientUrl}/polygonAmoy).parseUnits(value, 6) for USDC amounts (6 decimals, not 18).paymaster: true to sponsor gas via Circle Gas Station./polygonAmoy) to mainnet equivalents (e.g., /polygon) when migrating to production.TEST_API_KEY: to LIVE_API_KEY: when migrating to mainnet. Testnet keys cannot be used with mainnets.localhost or testnet domains will not work on the production domain.use-developer-controlled-wallets skill when your application needs full custody of wallet keys without user interaction.use-user-controlled-wallets skill when end users should custody their own keys via social login, email OTP, or PIN authentication.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.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。