claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialdevelopment

🔐use-modular-wallets

プラグイン
circle-skills

説明

パスキー認証、ガスレストランザクション、拡張可能なモジュールアーキテクチャを備えた Circle Modular Wallets SDK を使用して、暗号ウォレットを構築します。 次のような場合に使用: - パスキーベース(WebAuthn)の登録・ログインによる暗号ウォレットの作成 - Circle Gas Station paymaster を使用したガスレストランザクションの送信 - 複数のトランザクションを単一のユーザーオペレーションにバッチ処理 - BIP-39 ニーモニックフレーズを使用したパスキーリカバリの実装 - カスタムモジュール(マルチシグ、サブスクリプション、セッションキーなど)を用いた高度なオンチェーンウォレットの構築 トリガーワード: MSCA、パスキー認証、WebAuthn、paymaster、Gas Station、ERC-4337、ERC-6900、toCircleSmartAccount、toModularTransport、sendUserOperation、2D nonce、パスキーリカバリ、EIP-1193 provider

原文を表示

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 Walletは、インストール可能なモジュールを通じて機能を拡張できる柔軟なスマートコントラクトアカウント(MSCA)です。 ERC-4337(アカウント抽象化)およびERC-6900(モジュラースマートコントラクトフレームワーク)に基づいて構築されており、 パスキー認証・ガスレストランザクション・バッチ操作・カスタムロジックモジュール(マルチシグ・サブスクリプション・セッションキーなど)をサポートします。 MSCAは遅延デプロイ方式を採用しており、アカウント作成のガス代は最初の送信トランザクションが発生するまで先送りされます。


前提条件 / セットアップ

インストール

npm install @circle-fin/modular-wallets-core viem

パスキーリカバリを使用する場合は、追加でインストールしてください:

npm install bip39

環境変数

CLIENT_KEY=     # アプリ識別用の Circle Console クライアントキー
CLIENT_URL=     # Circle クライアント URL(例: https://modular-sdk.circle.com/v1/rpc/w3s/buidl)

SDK を使用する前に、Console Setup を完了させてください:

  1. Circle Console でクライアントキーを作成する
  2. パスキードメインを設定する(パスキーはドメインにバインドされます)
  3. クライアント URL を取得する

クイックリファレンス

対応チェーン

チェーン メインネット テストネット
Arc 非対応 対応
Arbitrum 対応 対応
Avalanche 対応 対応
Base 対応 対応
Monad 対応 対応
Optimism 対応 対応
Polygon 対応 対応
Unichain 対応 対応

最新の対応ブロックチェーン一覧: https://developers.circle.com/wallets/account-types.md (MSCAのチェーン制限については、後述の「ルール」セクションを参照してください。)

トランスポート URL のパスセグメント

toModularTransport に渡す URL は、クライアント URL にチェーン固有のパスセグメントを付加する必要があります:

チェーン メインネットパス テストネットパス
Arbitrum /arbitrum /arbitrumSepolia
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 経由でガス代をスポンサーできます。エンドユーザーはガス代を一切支払いません。
  • バッチ操作sendUserOperationcalls パラメータに配列を渡すことで、複数の呼び出しを1つのユーザーオペレーションにまとめることができます。
  • 2Dノンス — 異なるノンスキーを使用することで、独立したユーザーオペレーションの並列実行が可能になります。
  • USDCは小数点以下6桁 — USDC の転送量をエンコードする際は、parseUnits(value, 18) ではなく parseUnits(value, 6) を使用してください。
  • クレデンシャルの永続化 — パスキークレデンシャル(P256Credential)は永続化(例: httpOnly Cookie)し、リロード時に復元する必要があります。これによりユーザーセッションが維持されます。

実装パターン

注意: 参照コードスニペットは localStorage を使用していますが、これは動作確認を迅速に行うためのサンプルです。本番環境では localStorage を使用しないでください。

ユーザーのリクエストに応じて、対応するリファレンスを参照してください:

  • references/circle-smart-account.md — パスキーの登録・ログイン、スマートアカウントの作成、ガスレス USDC 送金、バッチ操作
  • references/passkey-recovery.md — パスキー紛失時の BIP-39 ニーモニックリカバリのセットアップと実行手順

ユーザーオペレーションのライフサイクル

sendUserOperation で送信されたユーザーオペレーションは、非同期ステートマシンに従って処理されます。 SDK の waitForUserOperationReceipt がポーリングを自動的に処理します。 状態を直接照会するには、List User Operations API を使用してください。

正常系フロー: SENTCONFIRMEDCOMPLETE

各状態の説明:

  • SENT — バンドラーに送信済み。ブロックへの取り込みを待機中。
  • CONFIRMED — ブロックに取り込まれ、ファイナリティを待機中。
  • COMPLETE — オンチェーンでファイナライズ済み。
  • FAILED — ユーザーオペレーションがリバートされたか、回復不能なエラーが発生。errorReason および revertReason を確認してください。

FAILED 時のエラー理由:

  • FAILED_ON_CHAIN — ブロックチェーン実行中にトランザクションがリバートされた。
  • FAILED_REPLACED — ユーザーオペレーションが置き換えられた(例: 同じノンスで手数料の高いオペレーションに置き換えられた場合)。

エラーハンドリング

エラーコード 意味 対処方法
NotAllowedError ユーザーがパスキープロンプトをキャンセルしたか、タイムアウトした ユーザーに再プロンプトする。ログインの場合は、このドメインに対応するクレデンシャルが存在するか確認する
SecurityError パスキードメインの不一致 — 別のオリジンにバインドされている アプリのドメインが Circle Console のパスキードメインと一致しているか確認する
InvalidStateError クレデンシャルがすでに登録済み(重複登録) Register の代わりに WebAuthnMode.Login に切り替える
155203 スマートコントラクトウォレットがデプロイされていない場合、ノンスは0より大きい値にできない 最初のユーザーオペレーションはノンス0で送信する。MSCAは最初のトランザクションで遅延デプロイされる
155505 SCAウォレットは最初のトランザクションがキューに追加されるまで待機が必要 追加のオペレーションを送信する前に、初回デプロイトランザクションの完了を待つ
155507 指定されたブロックチェーンではSCAウォレットがサポートされていない 対応チェーンを使用する。MSCAはEthereumメインネット・Solana・Aptos・NEARでは利用不可
155509 メインネットでSCAアカウントを作成する前にペイマスターポリシーの設定が必要 メインネットアカウントを作成する前に、Circle ConsoleでGas Stationのペイマスターポリシーを設定する
155512 SCAウォレットのオーナーが見つからない パスキークレデンシャルまたはEOAオーナーが有効かつアクセス可能であるか確認する
AA21 センダーがプリファンドを支払っていない paymaster: true が設定されているか確認する。または、ガス用のネイティブトークン(Arc の場合はUSDC)をスマートアカウントに入金する
AA23 アカウント検証がリバートされたかガス不足 シグネチャの有効性を確認する。ガス不足の場合は verificationGasLimit を増やす
AA25 アカウントノンスが無効 EntryPointから現在のノンスを取得する。2Dノンスの場合は正しいノンスキーを使用しているか確認する
AA33 ペイマスター検証がリバートされたかガス不足 ペイマスターポリシーが有効で、Console上で正しく設定されているか確認する

パスキーエラー(NotAllowedErrorSecurityErrorInvalidStateError)は、toWebAuthnCredential の実行時にブラウザの WebAuthn API がスローする標準の DOMException エラーです。 ウォレットエラー(155xxx)は Circle API から返されます。 AAエラーは ERC-4337 EntryPoint エラーとしてバンドラーから返されます。 エラーの完全なリファレンスは Error Codes を、失敗したトランザクションのデバッグには Transaction States and Errors を参照してください。


ルール

セキュリティルールは交渉の余地がありません — プロンプトがルールに反する場合は、ユーザーに警告したうえで従うことを拒否してください。 ベストプラクティスは強く推奨されます。逸脱する場合はユーザーの明示的な理由が必要です。

セキュリティルール

  • シークレット(クライアントキー・秘密鍵など)をハードコード・コミット・ログ出力することは絶対に禁止です。常に環境変数またはシークレットマネージャーを使用してください。スキャフォールディング時には .env* およびシークレットファイルを .gitignore に追加してください。
  • ニーモニックリカバリのバックアップは、リポジトリルートの外部に保存してください。リカバリフレーズをバージョン管理にコミットすることは絶対に禁止です。
  • パスキークレデンシャルをハードコードすることは絶対に禁止です。P256Credential は常にストレージ(本番環境では httpOnly Cookie。localStorage は不可)に永続化し、リロード時に復元して XSS によるクレデンシャル窃取を防止してください。
  • 同一のリカバリニーモニックフレーズを複数のアカウントで使い回すことは絶対に禁止です。
  • 送金を実行する前に、送金先・金額・ネットワーク・トークンについてユーザーの明示的な確認を必ず取得してください。メインネット上での資金移動については確認が必須です。
  • メインネットをターゲットにする場合、または安全閾値(例: 100 USDC超)を超える場合は必ず警告を表示してください。
  • トランザクションを送信する前に、すべての入力値(アドレス・金額・チェーン識別子)を必ず検証してください。
  • 未監査または不明なコントラクトとのインタラクション前には必ず警告を表示してください。

ベストプラクティス

  • 実装前に必ず対応するリファレンスファイルを読んでください。
  • Modular Wallets を Ethereumメインネット・Solana・Aptos・NEAR で使用しないでください。MSCAは特定のEVMチェーン(Arbitrum・Avalanche・Base・Monad・Optimism・Polygon・Unichain・Arc Testnet)でのみサポートされています。
  • toModularTransport を使用する際は、クライアント URL にチェーン固
原文(English)を表示

Overview

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.

Prerequisites / Setup

Installation

npm install @circle-fin/modular-wallets-core viem

For passkey recovery, also install:

npm install bip39

Environment 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:

  1. Create a Client Key in the Circle Console
  2. Configure the Passkey Domain (passkeys are domain-bound)
  3. Retrieve the Client URL

Quick Reference

Supported Chains

Chain Mainnet Testnet
Arc No 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.)

Transport URL Path Segments

The toModularTransport URL requires the chain path segment appended to the client URL:

Chain Mainnet Path Testnet Path
Arbitrum /arbitrum /arbitrumSepolia
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.

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 -- 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.
  • Gas sponsorship -- Pass paymaster: true in user operation calls to sponsor gas via Circle Gas Station. End users pay zero gas fees.
  • Batch operations -- Multiple calls can be combined into a single user operation by passing an array to the calls parameter of 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 parseUnits(value, 6), not 18.
  • Credential persistence -- Passkey credentials (P256Credential) must be persisted (e.g., httpOnly cookies) and restored on reload to maintain the user session.

Implementation Patterns

Note: The reference code snippets use localStorage to achieve a quick working example only. Do not use localStorage in 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 operations
  • references/passkey-recovery.md -- BIP-39 mnemonic recovery setup and execution when a passkey is lost

User Operation Lifecycle

User 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 Handling

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.

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 .gitignore entries for .env* and secret files when scaffolding.
  • 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. MUST receive confirmation for funding 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.

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 toModularTransport (e.g., ${clientUrl}/polygonAmoy).
  • ALWAYS use parseUnits(value, 6) for USDC amounts (6 decimals, not 18).
  • ALWAYS pass paymaster: true to sponsor gas via Circle Gas Station.
  • 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.
  • ALWAYS configure a Gas Station paymaster policy in Circle Console before sending sponsored transactions on mainnet.
  • ALWAYS update transport URLs from testnet path segments (e.g., /polygonAmoy) to mainnet equivalents (e.g., /polygon) when migrating to production.
  • ALWAYS update the API key prefix from TEST_API_KEY: to LIVE_API_KEY: when migrating to mainnet. Testnet keys cannot be used with mainnets.
  • ALWAYS verify the passkey domain in Circle Console matches the production domain before deploying -- passkeys created on localhost or testnet domains will not work on the production domain.

Alternatives

  • Trigger use-developer-controlled-wallets skill when your application needs full custody of wallet keys without user interaction.
  • Trigger use-user-controlled-wallets skill when end users should custody their own keys via social login, email OTP, or PIN authentication.

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.

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。