Overview
By default, when a user uses their Base Account within your app, the user must authorize every signature and transaction via a passkey prompt. This may be interruptive for your app’s user experience, particularly for use cases that require a high-volume of signatures or transactions, such as gaming. Sub Accounts enable you to create an Ethereum account derived from the parent Base Account that is specific to your app, with its own address, signing capabilities, and transaction history. This Sub Account is owned by another wallet, such as an embedded wallet or a local account, and can be configured to not require an explicit (passkey) confirmation from the user on every signature and transaction. Sub accounts can even transact with the balance of the parent account using Spend Permissions, allowing users to spend this balance without explicit passkey prompts.Prerequisites
Make sure you have set up Privy with Base Account before following this guide.Implementation
1. Set up your React app
First, ensure your app is configured to:- Show the Base Account as one of the external wallet options that users can use to connect to your application
- Create embedded wallets automatically on login by setting
config.embedded.ethereum.createOnLogin
to'all-users'
2. Create or get a Sub Account
After the user logs in, create a new Sub Account or get the existing Sub Account for the user that is tied to your app’s domain. First, get the connected wallet instances for your user’s embedded wallet and Base Account:wallet_getSubAccounts
RPC method. If the user does not have an existing Sub Account, create a new one for them using the wallet_addSubAccount
RPC:
3. Configure the SDK to use the embedded wallet for Sub Account operations
Configure the Base Account SDK to use the embedded wallet to control Sub Account operations. This allows the embedded wallet to sign messages and transactions on behalf of the Sub Account, avoiding the need for a separate passkey prompt. Use theuseBaseAccountSdk
hook from Privy’s React SDK to access the instance of the Base Account SDK directly, and use the SDK’s subAccount.setToOwnerAccount
method to configure the embedded wallet to sign on behalf of the Sub Account’s operations:
4. Complete Sub Account Setup
Here’s the complete code that showcases how to create or get an existing Sub Account for your user, and set the embedded wallet as the Sub Account’s owner:5. Sign messages and send transactions with the Sub Account
Once configured, you can sign and send transactions with the Sub Account using the Base Account’s EIP1193 provider. To ensure that signatures and transactions come from the Sub Account, for each of the following RPCs:personal_sign
: pass the Sub Account’s address, not the parent Base Account’s address, as the second parametereth_signTypedData_v4
: pass the Sub Account’s address, not the parent Base Account’s address, as the first parametereth_sendTransaction
: setfrom
in the transaction object to the Sub Account’s address, not the parent Base Account’s address
Sign a message
Send a transaction
Send a batch of transactions
Complete Example Component
Here’s a complete React component that demonstrates Sub Account creation and usage:Benefits of Sub Accounts
- Reduced Friction: Users don’t need to approve every transaction with a passkey
- Better UX: Seamless interactions for gaming and high-frequency use cases
- Security: Sub Accounts are still secured by the parent Base Account
- Spend Permissions: Sub Accounts can transact with the parent account’s balance
Next Steps
You can combine Sub Accounts with Spend Permissions to allow the Sub Account to spend from the balance of the parent Base Account ineth_sendTransaction
requests.
For more advanced Sub Account features and Spend Permissions, refer to the Base Account Sub Accounts guide.