Using Sub Accounts with Privy
How to enable Smart Wallet Sub Accounts in a Privy project
Overview
In this guide, you’ll learn how to enable Smart Wallet Sub Accounts in a Privy project. This allows your users to automatically create a Sub Account with Spend Permissions when connecting their wallet via Privy.
Skip ahead
If you want to skip the setup and see a working demo, check out the Sub Accounts Privy Demo:
What you’ll achieve
By the end of this guide, you will:
- Enable automatic Smart Wallet Sub Account creation for users authenticating with Privy
- Set up Spend Permissions for Sub Accounts on Base Sepolia
- Understand the required package versions and configuration
Requirements
- A Privy project
- Smart Wallet Sub Accounts are only available on the canary version of the Coinbase Wallet SDK and on Base Sepolia
- For now, you must also use a specific beta version of
@privy-io/react-auth
(see below)
1. Override Required Package Versions
Sub Accounts require the latest canary version of @coinbase/wallet-sdk
and a specific beta version of Privy React Auth. You must override these versions before installing packages.
Important:
If you already have a lock file or node_modules
, you must delete them before setting the overrides and reinstalling. Otherwise, the correct versions will not be installed and Sub Accounts will not work.
2. Update Your Privy Provider Configuration
To enable Sub Accounts, update your Privy Provider
configuration (usually in providers.tsx
or similar):
Explanation of Key Parameters
keysUrl
: Points to the Smart Wallet development environment. Sub Accounts only work in this environment.options: 'smartWalletOnly'
: Ensures only Smart Wallet mode is used.enableAutoSubAccounts: true
: Automatically creates a Sub Account when the user connects.defaultSpendLimits
: Sets Spend Permissions from the global Smart Wallet to the Sub Account on Base Sepolia (84532
).token
: The token address (native ETH in this example).allowance
: The max amount (in hex WEI) the Sub Account can spend in the period.period
: The time window for the allowance (in seconds, e.g., 86400 for 24h).
Note:
This guide only covers the automatic Sub Account creation flow, where a Sub Account is created and Spend Permissions are set as soon as the user connects their wallet. We are working with Privy to support flows where the user can first authenticate with their global Smart Wallet account and then create a Sub Account after. For now, only the automatic Sub Accounts flow is supported.
3. Test Your Setup
- Start your development server:
- Open your app and connect with Coinbase Wallet via Privy.
- You should see a prompt to create a Sub Account and Spend Permissions.
- You can now use the Sub Account to send transactions without pop-up confirmations.
Additional Resources
- Sub Accounts Privy Demo
- Sub Accounts Setup Guide
- Smart Wallet Sub Accounts Feature
- Privy Quickstart
- Discord #smart-wallet for questions or feedback