An embedded wallet is a non-custodial wallet managed within a user-facing application, abstracting away private key complexity. Unlike traditional wallets like MetaMask, users authenticate via familiar methods—email, social logins, or passkeys—while the application's backend securely orchestrates the underlying cryptographic operations. The core architectural challenge is balancing this seamless user experience with the security and self-custody principles of Web3. Key decisions involve choosing a signer abstraction (like ERC-4337 smart accounts), a key management strategy, and a gas sponsorship model.
How to Architect an Embedded Wallet Solution
How to Architect an Embedded Wallet Solution
A technical guide to designing secure, scalable embedded wallet systems for Web3 applications.
The foundation of your architecture is the signer. For Ethereum and EVM chains, the ERC-4337 standard for account abstraction is essential. It defines a system where a smart contract, the User Operation, acts as the user's account, enabling features like social recovery, batched transactions, and gas sponsorship. Instead of an Externally Owned Account (EOA) with a single private key, you deploy a smart contract wallet for each user. This contract's logic is controlled by an owner signer, which your backend manages via a Signer Service. Popular SDKs like ZeroDev, Biconomy, and Alchemy's Account Kit provide frameworks to implement this.
Secure key management is the most critical component. The private key for the owner signer must never be exposed to the frontend. A standard pattern uses a Hardware Security Module (HSM) or a cloud KMS (like AWS KMS or GCP Cloud KMS) to generate and store keys. The Signer Service requests signatures from the HSM, which performs the signing operation in isolation. For enhanced security and scalability, implement a key derivation scheme. A master key in the HSM can derive unique wallet keys for each user using a deterministic algorithm based on the user's ID, ensuring key isolation without managing thousands of individual HSM keys.
To completely remove gas fees for users, you need a paymaster infrastructure. A paymaster is an ERC-4337 contract that sponsors transaction gas fees on behalf of users. Your backend runs a Paymaster Service that holds native tokens, receives User Operations, validates them against custom rules (e.g., whitelisted actions, rate limits), and submits them with sponsored gas. You must monitor balances, handle different gas tokens across chains, and implement replenishment strategies. For development, services like Stackup, Pimlico, and Biconomy offer managed paymaster APIs; for production, you may need to run your own to control costs and policies.
A robust backend architecture typically involves several microservices: an Auth Service (handles OAuth/email magic links), the Signer Service (communicates with HSMs), the Paymaster Service, and an Indexer/Relayer. The Indexer listens for on-chain events related to the user's smart account and maintains an off-chain state for fast queries (e.g., token balances, transaction history). The Relayer bundles and submits User Operations to a bundler network. Use idempotency keys and queueing systems (like Redis or RabbitMQ) to handle signing requests reliably and prevent duplicate transactions under high load.
Finally, consider the user journey and security trade-offs. Provide clear onboarding, perhaps with recovery phrases or social guardians for emergency access. Audit all smart contracts, especially your wallet factory and paymaster. Use multi-party computation (MPC) for advanced key management if avoiding single points of failure. Monitor for anomalous behavior and set spending limits. By layering ERC-4337, secure HSMs, a reliable paymaster, and a decoupled backend, you can build an embedded wallet that is both user-friendly and enterprise-grade, ready to scale to millions of users.
Prerequisites and Core Decisions
Building an embedded wallet requires foundational technical choices that define security, user experience, and scalability. This guide outlines the core decisions you must make before writing your first line of code.
An embedded wallet is a non-custodial wallet where key management is abstracted from the end-user but remains under their ultimate control, typically integrated directly into your application's interface. Unlike traditional wallets like MetaMask, users don't manage seed phrases; instead, they authenticate via familiar Web2 methods (email, social login). The core architectural challenge is balancing this seamless onboarding with uncompromising security and user sovereignty. Your first decision is defining the custodial model: will you use a non-custodial model where you never touch private keys, a co-custodial model using multi-party computation (MPC), or a fully custodial solution? For most DeFi and dApp integrations, non-custodial or MPC-based approaches are standard to maintain trustlessness.
The next critical decision is your key management architecture. For a non-custodial experience, you typically generate a cryptographic secret for the user, split it, and distribute the shares. A common pattern uses Threshold Signature Scheme (TSS) with MPC, where key shares are held by the user's device and a secure cloud service (like AWS KMS or a dedicated MPC provider). No single party holds the complete key. Alternatively, you can use account abstraction via ERC-4337, creating a smart contract wallet where transaction logic is decoupled from the key. Each approach has trade-offs: MPC offers flexibility but operational complexity; smart accounts provide programmability but may have higher gas costs on some chains.
You must also select a blockchain stack. Will your wallet be EVM-only, or multi-chain? For EVM, decide on support for Layer 2s like Arbitrum, Optimism, or Polygon. For non-EVM chains (Solana, Cosmos, etc.), you'll need separate SDKs and RPC providers. Your choice dictates the SDKs you'll use: viem or ethers.js for EVM interactions, @solana/web3.js for Solana. You'll also need reliable RPC endpoints—consider services like Alchemy, Infura, or QuickNode for high availability and performance. Plan for gas sponsorship (paying fees for users) via paymaster services if you want a truly gasless experience, a key feature for mainstream adoption.
Finally, establish your security and compliance baseline. At a minimum, implement SOC 2 Type II controls for your infrastructure. Use hardware security modules (HSMs) or cloud KMS for any server-side key material. For user recovery, design a secure process—avoid plaintext backups. Common methods include encrypted cloud backups (where the user's password encrypts their share) or social recovery using trusted guardians. You must also plan for regulatory considerations like Travel Rule compliance if handling fiat on-ramps, and ensure your user onboarding includes necessary Know Your Customer (KYC) checks if required for your use case. These decisions form the bedrock of a secure, scalable embedded wallet solution.
How to Architect an Embedded Wallet Solution
A technical guide to designing secure, scalable, and user-friendly embedded wallets for Web3 applications.
An embedded wallet is a non-custodial wallet managed within a traditional application, abstracting blockchain complexity for end-users. Unlike standalone wallets like MetaMask, the private key is secured by the application's backend, often using social logins (Google, Apple) or email as the authentication factor. The core architectural challenge is balancing security, user experience, and scalability. Key components include a key management service, a transaction relayer, and a user session manager. This architecture is fundamental for mainstream adoption, enabling familiar onboarding while maintaining user sovereignty over assets.
The security model is paramount and typically employs a multi-party computation (MPC) or account abstraction (ERC-4337) approach. In an MPC setup, the private key is split into shares; the client holds one share, and a secure server holds another, requiring both to sign. For ERC-4337, a smart contract wallet is deployed for the user, with logic allowing the application to sponsor gas and manage session keys. Both models prevent the application from having unilateral control. You must also implement secure key generation, rotation policies, and audit logging. Services like Privy, Dynamic, and Capsule provide SDKs that abstract these complex security layers.
The backend architecture requires several dedicated services. A Key Management Service (KMS) securely generates, stores, and orchestrates signatures for key shares. A Relayer Service submits and funds user transactions, handling gas estimation and sponsorship to eliminate the need for users to hold native tokens. A User Session Service validates authentication tokens (e.g., from Firebase Auth) and issues time-bound session keys to the client for signing. These services should be stateless where possible, with secrets stored in hardware security modules (HSMs) or cloud KMS like AWS KMS or GCP Cloud HSM.
On the client side, the SDK must be lightweight and framework-agnostic. It handles authentication flows, requests session keys from the backend, and constructs transaction objects. For MPC, it manages the local key share in secure storage (e.g., Android Keystore, iOS Keychain). The SDK communicates with your backend services and the blockchain via RPC providers like Alchemy or Infura. A critical design pattern is off-chain signatures: the client signs a message, the backend signs with its share, and the relayer broadcasts the combined signature, improving speed and reliability.
Scalability and chain abstraction are next-level considerations. Your architecture should support multiple EVM and non-EVM chains through a unified interface. Use a smart account factory (for ERC-4337) or multi-chain MPC nodes to deploy or derive wallets across networks. Implement caching for chain metadata and RPC failover to ensure high availability. Cost management is also crucial; design your relayer with gas price optimization, fee sponsorship rules, and usage analytics to prevent abuse. Monitoring wallet creation, transaction success rates, and gas spend is essential for operational health.
Finally, integrate this wallet into your application's user journey. The flow begins with traditional login, followed by silent wallet creation or recovery. Design for gradual onboarding—the user might not need to interact with the wallet until their first transaction. Provide clear in-app views for asset balances, transaction history, and settings. Always include a recovery mechanism, such as encrypted backup shards stored with the user's cloud provider or social recovery guardians. By following this architectural blueprint, you can build a seamless gateway that bridges Web2 users into the decentralized ecosystem.
Essential Tools and Documentation
These tools and references cover the core building blocks required to architect a secure, production-grade embedded wallet solution. Each card focuses on a specific architectural layer, from key management to session handling and recovery.
Transaction Policy, Risk Controls, and Monitoring
Production embedded wallets enforce transaction-level policy controls to limit damage from compromised sessions or malicious contracts.
Recommended controls:
- Contract allowlists and blocklists
- Per-transaction and daily spend limits
- Human-readable simulation before signing
- Automatic revocation of stale session keys
Advanced teams integrate:
- Onchain simulation against forked state
- MEV and phishing contract detection
- Real-time alerts for abnormal signing behavior
These controls are typically enforced at the smart wallet layer, not the SDK layer. Logging, monitoring, and alerting should be treated as first-class components, especially for consumer-facing applications with large user bases.
Key Management Architecture Comparison
Comparison of three primary approaches for managing private keys in embedded wallets, balancing security, user experience, and custody.
| Feature / Metric | MPC-Based | Smart Account (ERC-4337) | Hybrid (MPC + Smart Account) |
|---|---|---|---|
Private Key Custody | Distributed (MPC nodes) | On-chain (Smart Account) | Distributed (MPC for signer) |
User Recovery | Social / Cloud Backup | Social Recovery Modules | MPC + Social Recovery |
Gas Abstraction | Requires Relayer | Native via Paymasters | Native via Paymasters |
Sign-in Method | Email/Social (Web2) | EOA + Smart Account | Email/Social + Smart Account |
On-chain Footprint | EOA wallet only | Smart Contract | Smart Contract |
Approx. Tx Cost (L2) | $0.01 - $0.05 | $0.02 - $0.10 | $0.03 - $0.12 |
Protocol Examples | Web3Auth, Lit Protocol | Safe{Core}, Biconomy, ZeroDev | Candide, Dynamic |
Primary Security Model | Threshold Cryptography | Smart Contract Audits & Modules | Threshold + Smart Contract |
Implementation by Platform
Smart Account Architecture
Account Abstraction (ERC-4337) is the dominant standard for embedded wallets on Ethereum, Polygon, Arbitrum, and other EVM chains. It separates the verification logic (signature) from the execution logic (transaction), enabling features like social recovery, gas sponsorship, and batch transactions.
Key Components:
- UserOperation: A pseudo-transaction object submitted to a mempool.
- Bundler: A network actor that packages UserOperations into on-chain transactions.
- Paymaster: A contract that can sponsor transaction gas fees for users.
- EntryPoint: A singleton contract that orchestrates the verification and execution flow.
Implementation Flow:
- Generate a smart contract wallet address using
CREATE2for deterministic deployment. - Users sign
UserOperationmessages with their preferred method (EOA, WebAuthn, MPC). - A bundler submits the operation to the EntryPoint contract.
- The EntryPoint validates the signature via the wallet's verification logic and executes the intended calls.
Use SDKs like ZeroDev, Biconomy, or Alchemy's Account Kit to abstract this complexity.
How to Architect an Embedded Wallet Solution
Embedded wallets abstract away private key management, enabling seamless onboarding. This guide covers the core architectural decisions for building a secure, scalable solution.
An embedded wallet is a non-custodial wallet where the signing keys are generated, encrypted, and stored on behalf of the user, typically via a social login or passkey. Unlike traditional wallets (e.g., MetaMask), users don't manage seed phrases. The core architectural challenge is balancing security—maintaining non-custodial ownership—with user experience. Key components include a key management service for secure generation and storage, a signer service to process transactions, and a recovery mechanism (like social or multi-party computation).
The first decision is choosing a signing scheme. For EVM chains, common approaches are Externally Owned Accounts (EOAs) using ERC-4337 account abstraction via smart accounts (e.g., Safe, Biconomy, ZeroDev), or programmable key pairs like Turnkey or Privy. Smart accounts offer superior flexibility with features like batched transactions and gas sponsorship but introduce smart contract deployment gas costs. Programmable key pairs use standard ECDSA but manage keys in secure hardware, offering a simpler model for straightforward transfers.
User onboarding flow starts with authentication. Use OAuth (Google, GitHub), WebAuthn/Passkeys, or email magic links. Upon first login, your backend should call the key management service to generate a new wallet. The private key must never be exposed to the frontend in plaintext. Instead, the service returns an encrypted key share or a signerId. For recovery, implement social recovery using guardians or a multi-party computation (MPC) threshold scheme, where keys are split and distributed, preventing a single point of failure.
The signer service is critical. It receives transaction requests from your app, retrieves and decrypts the necessary key material in its secure environment, signs the transaction, and broadcasts it to the network. This service must be heavily fortified against attacks, using hardware security modules (HSMs) or cloud KMS like AWS KMS or GCP Cloud HSM. Audit trails and rate limiting are essential. For scalability, design the signer to be stateless, with key material fetched from the secure store per request.
Integrate this architecture into your application. Frontend SDKs like Privy, Dynamic, or Magic simplify this, providing React hooks for wallet connection and transaction signing that abstract the backend calls. For a custom build, your frontend will interact with your backend API, which in turn communicates with your key management and signer services. Always include a clear user interface for viewing assets, transaction history, and managing recovery settings. Test extensively on testnets like Sepolia before mainnet deployment.
Security and compliance are paramount. Since you manage key encryption, you are responsible for securing the encryption keys separately from the encrypted wallet keys. Follow SOC 2 principles and consider regulatory aspects if handling fiat on-ramps. Regularly audit your entire stack and use multi-signature schemes for treasury or admin operations. An open-source reference for MPC-based architecture is Web3Auth's tKey, while Safe{Core} Account Kit provides tools for smart account implementation.
Implementing a Transaction Relayer
A transaction relayer is a backend service that pays gas fees on behalf of users, enabling seamless onboarding and abstracting blockchain complexity. This guide covers the core architecture for building one.
A transaction relayer (or gas relayer) is a critical component of an embedded wallet solution. It functions as a meta-transaction processor, allowing users to sign and submit transactions without holding the native blockchain token (e.g., ETH for gas). The relayer receives the user's signed payload, validates it, wraps it with its own payment, and broadcasts it to the network. This architecture enables gasless transactions, which are essential for mainstream adoption by removing a major friction point for new users.
The core system involves three key actors: the User's Application (frontend), the Relayer Service (backend), and the Blockchain. The flow begins when the user's app creates a transaction request. Instead of requiring the user to pay gas, the app sends a signed EIP-712 or EIP-4337 UserOperation to your relayer endpoint. This signature proves user intent without exposing private keys. The relayer must then perform critical checks: verifying the signature's validity, ensuring the user has sufficient allowance for any token transfers, and applying rate limits or spam prevention logic.
For implementation, a Node.js service using Ethers.js v6 or Viem is common. Your relayer needs a funded wallet. Upon receiving a request, it should reconstruct the transaction, estimate gas, and apply a sponsorship policy. This policy defines which users or transaction types are eligible for gas sponsorship. After validation, the relayer signs and sends the transaction, returning the txHash to the user. It's crucial to implement robust error handling and logging for transaction status (pending, confirmed, failed).
Security is paramount. Always use nonces to prevent replay attacks. Validate that the signed transaction's chainId matches your expected network. Consider implementing a whitelist for allowed target contracts or function selectors to prevent misuse. For scalability, design your relayer to be stateless, using a database to track processed requests and prevent double-spending of gas. Services like OpenZeppelin Defender or Gelato Network can be integrated to automate and secure relay logic.
To manage costs, implement a sustainable business model. This can involve using ERC-20 gas abstraction where users pay fees in a stablecoin, subscription plans for developers, or utilizing Paymaster contracts in Account Abstraction (EIP-4337) bundles. The UserOperation standard is becoming the preferred method, as it allows bundling multiple operations and enables more sophisticated sponsorship logic directly in smart contracts, reducing relayer complexity.
Frequently Asked Questions
Common technical questions and solutions for developers building embedded, non-custodial wallet solutions.
An embedded wallet is a non-custodial wallet whose user interface and onboarding flow are integrated directly into a dApp or service, abstracting away blockchain complexity. Unlike traditional wallets like MetaMask where users must install an extension and manage seed phrases upfront, embedded wallets use signer abstraction. They typically generate a cryptographic key pair for the user (often via social login or passkeys) and secure it client-side, allowing immediate interaction with the dApp.
Key architectural differences:
- Onboarding: Uses Web2 methods (email, social logins) instead of seed phrase generation.
- Key Management: Private keys are often secured in the user's device storage (e.g., IndexedDB, Secure Enclave) or via MPC (Multi-Party Computation) services, not a browser extension.
- User Experience: Removes the need for prior crypto knowledge, enabling a seamless first transaction.
Conclusion and Next Steps
This guide has outlined the core components and security considerations for building an embedded wallet solution. The next steps involve implementing these patterns and exploring advanced integrations.
You should now understand the fundamental architecture of an embedded wallet system: a non-custodial model where the user retains control of their keys, secured by a social login or passkey for key recovery, with all blockchain interactions abstracted through a gas sponsorship layer and a smart account like an ERC-4337 account. This design provides a user experience comparable to Web2 while maintaining the security and self-sovereignty of Web3. The key is to treat the embedded wallet not as a simple keypair but as a programmable, upgradable identity layer for your application.
For implementation, start by selecting and integrating core infrastructure. Choose a wallet-as-a-service (WaaS) provider like Privy, Dynamic, or Magic to handle key management and social logins. Deploy a Paymaster contract, either using a service like Biconomy or Pimlico or building your own, to manage gas sponsorship policies. Finally, ensure your application's smart contracts are compatible with the chosen account abstraction standard, allowing your user's smart accounts to interact with them seamlessly. Testing on a testnet like Sepolia or Amoy is essential before mainnet deployment.
Looking ahead, consider advanced features to enhance your solution. Implement session keys for granting limited transaction permissions to dApps, enabling seamless interactions without constant wallet pop-ups. Explore multi-chain support using solutions like the Chain Abstraction Stack to let users access assets and dApps across Ethereum, Polygon, and Solana from a single interface. Finally, plan for account recovery upgrades, such as integrating multi-party computation (MPC) for distributed key management or adding trusted guardians as defined in ERC-4337, to further strengthen user security and trust in your platform.