use-user-controlled-wallets
Overview
User-controlled wallets are non-custodial wallets where end users maintain control over their private keys and assets. Users authorize all sensitive operations (transactions, signing, wallet creation) through a challenge-response model that ensures user consent before execution. Multi-chain support includes EVM chains, Solana, and Aptos.
Prerequisites / Setup
Installation
npm install @circle-fin/user-controlled-wallets@latest @circle-fin/w3s-pw-web-sdk@latest vite-plugin-node-polyfills
Vite Configuration
The SDKs depends on Node.js built-ins (buffer, crypto, etc.) that are not available in the browser. Add vite-plugin-node-polyfills to your Vite config:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { nodePolyfills } from "vite-plugin-node-polyfills";
export default defineConfig({
plugins: [react(), nodePolyfills()],
});
Environment Variables
# Backend
CIRCLE_API_KEY= # Circle API key
# Frontend
CIRCLE_APP_ID= # App ID from Wallets > User Controlled > Configurator
Backend SDK Initialization
Uses @circle-fin/user-controlled-wallets for all server-side operations (user creation, challenge creation, transaction queries).
import { initiateUserControlledWalletsClient } from "@circle-fin/user-controlled-wallets";
const circleClient = initiateUserControlledWalletsClient({
apiKey: process.env.CIRCLE_API_KEY!,
});
Frontend SDK Initialization
Uses @circle-fin/w3s-pw-web-sdk for user-facing operations (challenge execution, auth flows, PIN/OTP/OAuth UI).
import { W3SSdk } from "@circle-fin/w3s-pw-web-sdk";
const sdk = new W3SSdk({ appSettings: { appId: circleAppId } });
IMPORTANT: You must call sdk.getDeviceId() after SDK initialization. This establishes a session with Circle's service via an iframe. Without this call, sdk.execute() will silently fail.
For email OTP and social login, the SDK must be initialized with a login callback as the second argument. See the corresponding reference files for details.
Core Concepts
Account Types
User-controlled wallets support EOA and SCA account types, chosen at wallet creation.
EOA (Externally Owned Account): No creation fees, higher TPS, broadest chain support (EVM, Solana, Aptos). Requires native tokens for gas on EVM chains. Gas sponsorship only available on Solana via feePayer.
SCA (Smart Contract Account): ERC-4337 account abstraction. Gas sponsorship via Circle Gas Station paymaster, batch operations, flexible key management. EVM-only (no Solana/Aptos). First outbound transaction incurs gas for lazy deployment. Avoid on Ethereum mainnet due to high gas -- use on L2s (Arbitrum, Base, Polygon, Optimism).
For supported blockchains by account type: https://developers.circle.com/wallets/account-types
Architecture
User-controlled wallets involve three parties:
-
End User (Client) -- The person using a web app or mobile app. They interact with the developer's frontend, authenticate (PIN, email OTP, or social login), and approve all sensitive operations (wallet creation, transactions, signing) through Circle's hosted UI via
@circle-fin/w3s-pw-web-sdk. Users retain full control of their private keys -- neither the developer nor Circle can act on their behalf. -
Developer Service (Backend) -- The developer's own server. It holds the Circle API key, manages user sessions, tracks usage, and enforces application-level guardrail rules (e.g., spending limits, allowlisted addresses, rate limiting). It submits requests to Circle's API using
@circle-fin/user-controlled-wallets. Developers register a developer account through the Circle Developer Console to get access to Circle Wallet services. For developer-specific account setup, see theuse-developer-controlled-walletsskill. -
Circle Wallet Service (API) -- Circle's infrastructure that manages wallet creation, transaction submission, key management (MPC-based), and blockchain interactions. It provides the non-custodial guarantee: developers get read access for security monitoring and auditing, while users keep full control of their wallets and assets. Circle enforces platform-level compliance screening (e.g., OFAC sanctions checks) on transactions.
Request flow:
End User (browser/mobile)
| authenticates & approves challenges
v
Developer Service (backend server)
| adds API key, enforces app-level guardrails, tracks usage
v
Circle Wallet Service (API)
| manages wallets, enforces compliance screening, submits transactions
v
Blockchain
This three-tier architecture ensures separation of concerns: the client handles user interaction and consent, the developer service handles business logic and application-level guardrails, and Circle handles cryptographic operations, compliance screening, and blockchain interactions.
Challenge-Response Model
All sensitive operations (wallet creation, transactions, signing) follow this pattern:
- Backend creates the operation via Circle API -> Circle returns a
challengeId - Frontend calls
sdk.setAuthentication({ userToken, encryptionKey })thensdk.execute(challengeId, callback)-> user approves via Circle's hosted UI - Callback fires with result or error
Authentication Methods
| Method | Console Setup | How userToken Is Obtained |
|---|---|---|
| PIN | None | Backend calls createUserToken({ userId }) (60 min expiry) |
| Email OTP | SMTP config | SDK login callback after OTP verification |
| Social Login | OAuth client ID | SDK login callback after OAuth redirect |
Developer Access and Limitations
Developers can read wallet data, transaction history, and user information -- either through the Circle Developer Console UI or programmatically via the API. However, developers do not have access to users' private keys and cannot control user wallets to send transactions, sign messages, or perform any on-chain operations on a user's behalf. All such operations require the user to authorize them through the challenge-response model.
Developers also cannot help a user recover their wallet if the user loses access to their authentication method (social account, email, or PIN code and security questions). Account recovery is entirely dependent on the user's ability to re-authenticate. Inform users of this limitation during onboarding so they understand the importance of maintaining access to their chosen authentication method.
User Access and Limitations
Users can only access their own wallets and resources. They have no access to other users' wallets, transactions, or any other resources. Users also have no access to developer-controlled wallets or resources -- the two wallet types are fully isolated from each other.
Implementation Patterns
Note: The reference code snippets use
localStorageto achieve a quick working example only. Do not uselocalStoragein production.
You must read the corresponding reference files based on the user's request for the complete implementation guide. Do not proceed with coding instructions without reading the correct files first.
-
Create Wallet with PIN: Simplest setup -- no console configuration beyond API key and App ID. Users set a PIN and security questions through Circle's hosted UI. READ
references/create-wallet-pin.md. -
Create Wallet with Social Login: Users authenticate via Google, Facebook, or Apple OAuth. Requires OAuth client ID configured in Circle Console. READ
references/create-wallet-social-login.md. -
Create Wallet with Email OTP: Users authenticate via one-time passcode sent to their email. Requires SMTP configuration in Circle Console. READ
references/create-wallet-email-otp.md. -
Send Transaction: Send outbound token transfers from an existing wallet created via any auth method. Includes fee estimation, transaction acceleration, and cancellation. READ
references/send-transaction.md. -
Sign Messages: Sign messages from a user-controlled wallet. Covers EIP-191 message signing, EIP-712 typed data, and raw transaction signing. READ
references/sign-message.md. -
Execute Smart Contracts: Execute smart contract functions via ABI signature or raw calldata. Includes gas estimation for contract execution. READ
references/contract-execution.md. -
Wallet Management: Update wallet metadata. READ
references/wallet-management.md.
Transaction Lifecycle
All on-chain operations (transfers, contract executions) follow the same asynchronous state machine. Poll with circleClient.getTransaction({ userToken, id }) until a terminal state is reached.
Happy path: INITIATED -> CLEARED -> QUEUED -> SENT -> CONFIRMED -> COMPLETE
Intermediate states:
INITIATED-- Request accepted, not yet validated or checked.WAITING-- In queue for validation and compliance checks.CLEARED-- Finish compliance checks.QUEUED-- Queued for submission to the blockchain.SENT-- Submitted to the blockchain, awaiting confirmation.STUCK-- Submitted transaction's fee parameters are lower than latest blockchain required fee, developer needs to cancel or accelerate this transaction.CONFIRMED-- Included in a block, awaiting finality.
Terminal states:
COMPLETE-- Transaction succeeded and is finalized on-chain.FAILED-- Transaction reverted or encountered an unrecoverable error.DENIED-- Transaction was rejected by risk screening.CANCELLED-- Transaction was cancelled before on-chain submission.
Always wait until a terminal state before treating any transaction as done. For debugging failed or denied transactions, see Transaction Errors.
Error Handling
| Error Code | Meaning | Action |
|---|---|---|
| 155106 | User already initialized | Fetch existing wallets instead of creating |
| 155104 | Invalid user token | Re-authenticate user (token expired) |
| 155101 | Invalid device token / User not found | Re-create device token or user |
| 155130 | OTP token expired | Request new OTP |
| 155131 | OTP token invalid | Request new OTP |
| 155133 | OTP value invalid | User should re-enter code |
| 155134 | OTP value not matched | User should re-enter code |
| 155146 | OTP invalid after 3 attempts | Request new OTP (locked out) |
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 (API keys, encryption keys). ALWAYS use environment variables or a secrets manager. Add
.gitignoreentries for.env*and secret files when scaffolding. - ALWAYS implement both backend and frontend. The API key MUST stay server-side -- frontend-only builds would expose it.
- 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.
- ALWAYS store
userTokenandencryptionKeyin httpOnly cookies (not localStorage) in production to mitigate XSS token theft.
Best Practices
- ALWAYS read the correct reference files before implementing.
- ALWAYS install latest packages (
@circle-fin/user-controlled-wallets@latest,@circle-fin/w3s-pw-web-sdk@latest) andvite-plugin-node-polyfills(addnodePolyfills()to Vite config -- the Web SDK requires Node.js built-in polyfills). - ALWAYS call
sdk.getDeviceId()after init andsdk.setAuthentication({ userToken, encryptionKey })beforesdk.execute(). WithoutgetDeviceId(), execute silently fails. - NEVER use SCA on Ethereum mainnet (high gas). Use EOA on mainnet, SCA on L2s.
- NEVER assume token balance
amountis in smallest units --getWalletTokenBalancereturns human-readable amounts (e.g., "20" for 20 USDC). - ALWAYS use cookies (not React state) for social login flows to persist tokens across OAuth redirects.
- ALWAYS default to testnet. Require explicit user confirmation before targeting mainnet.
- ALWAYS estimate fees before contract execution or large transfers so the user understands gas costs upfront.
- ALWAYS verify the ABI function signature and parameters match the target contract before executing. Incorrect signatures will revert and waste gas.
- ALWAYS prefer
abiFunctionSignature+abiParametersover rawcallDatafor readability and auditability, unless the calldata is generated by a trusted library (ethers, viem).
Alternatives
- Use the
use-modular-walletsskill for passkey-based smart accounts with gas sponsorship using ERC-4337 and ERC-6900. - Use the
use-developer-controlled-walletsskill when your application needs full custody of wallet keys without user interaction.
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.
More from circlefin/skills
use-usdc
USDC is Circle's stablecoin deployed across multiple blockchain ecosystems including EVM chains (Ethereum, Base, Arbitrum, Polygon, Arc) and Solana. Use this skill to check balances, send transfers, approve spending, and verify transactions. Triggers on: USDC balance, send USDC, transfer USDC, approve USDC, USDC allowance, verify USDC transfer, USDC contract address, USDC on Solana, Solana USDC, check balance, SPL token, Associated Token Account, ATA, ERC-20 USDC, parseUnits, formatUnits, 6 decimals, viem, @solana/kit.
143use-arc
Provide instructions on how to build with Arc, Circle's blockchain where USDC is the native gas token. Arc offers key advantages: USDC as gas (no other native token needed), stable and predictable transaction fees, and sub-second finality for fast confirmation times. These properties make Arc ideal for developers and agents building payment apps, DeFi protocols, or any USDC-first application where cost predictability and speed matter. Use skill when Arc or Arc Testnet is mentioned, working with any smart contracts related to Arc, configuring Arc in blockchain projects, bridging USDC to Arc via CCTP, or building USDC-first applications. Triggers: Arc, Arc Testnet, USDC gas, deploy to Arc, Arc chain, stable fees, fast finality.
137use-developer-controlled-wallets
Create and manage Circle developer-controlled wallets where the application retains full custody of wallet keys on behalf of end-users. Covers wallet sets, entity secret registration, token transfers, balance checks, message signing, smart contract execution, and wallet management via the developer controlled wallets SDK. Triggers on: developer-controlled wallets, dev-controlled wallets, create wallet, wallet set, entity secret, transfer tokens, check balance, EOA wallet, SCA wallet, initiateDeveloperControlledWalletsClient, createWalletSet, createWallets, custody wallet, sign message, sign transaction, sign typed data, contract execution, execute contract, call contract, wallet upgrade, derive wallet, estimate fee, accelerate transaction, cancel transaction.
135bridge-stablecoin
Build USDC bridging with Circle App Kit or standalone Bridge Kit SDK and Crosschain Transfer Protocol (CCTP). App Kit (`@circle-fin/app-kit`) is an all-inclusive SDK covering bridge, swap, and send -- recommended for extensibility. Bridge Kit (`@circle-fin/bridge-kit`) is a standalone package for bridge-only use cases. Neither requires a kit key for bridge operations. Supports bridging USDC between EVM chains, between EVM chains and Solana, and between any two chains on Circle Wallets (i.e Developer-Controlled Wallets or Programmable wallets). Use when: bridge USDC, setting up Bridge Kit adapters (Viem, Ethers, Solana Kit, Circle Wallets), handling bridge events, collecting custom fees, configuring transfer speed, or using the Forwarding Service. Triggers on: Bridge Kit, App Kit, bridge USDC, crosschain transfer, CCTP, move USDC between chains, @circle-fin/bridge-kit, @circle-fin/app-kit, adapter-viem, adapter-ethers, adapter-solana-kit, forwarding service, bridge routes.
131use-circle-wallets
Choose and implement the right Circle wallet type for your application. Compares developer-controlled, user-controlled, and modular (passkey) wallets across custody model, key management, account types, blockchain support, and use cases. Use whenever blockchain wallet integrations are required for onchain application development. Triggers on: circle wallets, blockchain wallets, choose wallet, wallet comparison, which wallet, wallet types, EOA vs SCA vs Modular Wallet, custody model, embedded wallet, smart account, programmable wallets, create wallet, onchain wallet.
124use-smart-contract-platform
Deploy, import, interact with, and monitor smart contracts using Circle Smart Contract Platform APIs. Supports bytecode deployment, template contracts (ERC-20/721/1155/Airdrop), ABI-based read/write calls, and webhook event monitoring. Keywords: contract deployment, smart contract, ABI interactions, template contracts, event monitoring, contract webhooks, bytecode, ERC-1155, ERC-20, ERC-721.
124