Index of every page on this site: llms.txt
All skills
circlefin avatar

/use-modular-wallets

@a045767
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/circlefin/skills/use-modular-wallets

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencespasskey-recovery.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Passkey Recovery for Circle Smart Accounts

Reference implementation for setting up and executing wallet recovery using a BIP-39 mnemonic phrase to register a new passkey when the original is lost.

Source: passkey-recovery example

Environment Variables

Scaffolding (Next.js vs Vite pairs and fixed Client URL) lives in SKILL.md. This example uses Vite:

VITE_CLIENT_KEY=
VITE_CLIENT_URL=https://modular-sdk.circle.com/v1/rpc/w3s/buidl

Setup

import { createPublicClient, type Hex } from 'viem'
import { polygonAmoy } from 'viem/chains'
import { english, generateMnemonic, mnemonicToAccount } from 'viem/accounts'
import {
  type P256Credential,
  type SmartAccount,
  type WebAuthnAccount,
  createBundlerClient,
  toWebAuthnAccount,
} from 'viem/account-abstraction'
import {
  recoveryActions,
  toCircleSmartAccount,
  toModularTransport,
  toPasskeyTransport,
  toWebAuthnCredential,
  WebAuthnMode,
} from '@circle-fin/modular-wallets-core'
import { validateMnemonic } from 'bip39'

const clientKey = import.meta.env.VITE_CLIENT_KEY as string
const clientUrl = import.meta.env.VITE_CLIENT_URL as string

const passkeyTransport = toPasskeyTransport(clientUrl, clientKey)
const modularTransport = toModularTransport(`${clientUrl}/polygonAmoy`, clientKey)

const client = createPublicClient({
  chain: polygonAmoy,
  transport: modularTransport,
})

// Extend bundler client with recovery actions for managing account recovery
const bundlerClient = createBundlerClient({
  chain: polygonAmoy,
  transport: modularTransport,
}).extend(recoveryActions)

Recovery Setup (while user has access)

Step 1: Generate Recovery Key

Generate a BIP-39 mnemonic and derive the recovery EOA address. The user must save this phrase securely -- it is the only way to recover the account if the passkey is lost.

const mnemonic = generateMnemonic(english)
const recoveryEoa = mnemonicToAccount(mnemonic)
const recoveryAddress: Hex = recoveryEoa.address

// Display mnemonic to user and instruct them to save it securely

Step 2: Register Recovery Address On-Chain

Register the recovery EOA address with the smart account. This is an on-chain transaction that links the recovery address to the account.

await bundlerClient.registerRecoveryAddress({
  account,           // the user's existing Circle Smart Account
  recoveryAddress,   // EOA address derived from the mnemonic
  paymaster: true,
})

Recovery Execution (when passkey is lost)

Step 3: Validate Mnemonic and Create New Passkey

Prompt the user for their saved mnemonic, validate it, and register a new passkey credential.

if (!validateMnemonic(userEnteredMnemonic.trim())) {
  throw new Error('Invalid recovery phrase')
}

const newCredential = await toWebAuthnCredential({
  transport: passkeyTransport,
  mode: WebAuthnMode.Register,
  username: `${originalUsername}-recovered-${Date.now()}`,
})

Step 4: Execute Recovery

Use the mnemonic EOA to add the new passkey as an owner. This does NOT remove the old passkey; if it may have been stolen rather than lost, remove it with a separate owner-removal flow (Set up passkey recovery).

const localAccount = mnemonicToAccount(userEnteredMnemonic.trim())

// Create a temporary smart account using the recovery EOA as owner
const tempAccount = await toCircleSmartAccount({
  client,
  owner: localAccount,
})

// Adds newCredential as an owner
await bundlerClient.executeRecovery({
  account: tempAccount,
  credential: newCredential,
  paymaster: true,
})

// Persist the new credential for future sessions
localStorage.setItem('credential', JSON.stringify(newCredential))

Expected Flow Summary

  1. Setup: User registers passkey -> generates mnemonic -> registers recovery address on-chain
  2. Loss: Original passkey becomes inaccessible (lost device, deleted credential)
  3. Recovery: User enters mnemonic -> creates new passkey -> executeRecovery adds it as an owner on-chain
  4. Result: The new passkey can sign; the old passkey is NOT removed (see Step 4)

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

2 warnings15d5 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    The skill provides a secure implementation guide for building modular crypto wallets using the Circle SDK. It incorporates strong security practices, including mandatory environment variable usage for secrets, warnings against insecure credential storage, and explicit user confirmation steps for sensitive blockchain operations.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: MEDIUM · 1 issue

  • Runlayer8mo

    3/3 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at a045767. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated 3 weeks ago
requirements
{
  "runtimes": [],
  "connectors": []
}

README badge

README badge for circlefin/skills/use-modular-wallets