Sub Accounts Reference
Overview
The Coinbase Wallet SDK now supports Sub Accounts, allowing apps to create and manage additional smart contract accounts for users. Sub Accounts can have multiple owners and operate as smart contract wallets with enhanced security and flexibility.
Sub Account scope
Sub Accounts are currently scoped to an application’s fully qualified domain name (FQDN). This means that a user has one sub account for your application, and it cannot be used on other applications on separate domains.
Getting Started
Installation
Basic Setup with Sub Account Support
Creating a Sub Account
Getting a Sub Account
Adding an Owner to a Sub Account
You can add owners to a Sub Account by providing either an address or a public key.
Using a Sub Account for Transactions
Once a Sub Account is created, you can use it to sign and send transactions:
API Reference
SDK Configuration
Sub Account Methods
sdk.subaccount.create(account)
Creates a new Sub Account.
Parameters:
account
: An object with details about the account to createtype
: ‘create’ | ‘deployed’ | ‘undeployed’keys
: Array of key objects (for ‘create’ type)type
: ‘address’ | ‘p256’ | ‘webcrypto-p256’ | ‘webauthn-p256’key
: Hex string of the public key
Returns: Promise<SubAccountInfo>
sdk.subaccount.get()
Gets the current Sub Account, or connects to one if none exists.
Returns: Promise<SubAccountInfo>
sdk.subaccount.addOwner(options)
Adds an owner to a Sub Account.
Parameters:
options
: Object with details about the owner to addchainId
: Chain ID (number)address
: Address of the owner (optional)publicKey
: Public key of the owner (optional)
Returns: Promise<string>
- Response from the smart contract call
sdk.subaccount.setSigner(toSubAccountSigner)
Sets the signer function for Sub Account operations.
Parameters:
toSubAccountSigner
: Function that returns a Promise resolving to a signer object
Technical Details
Sub accounts are implemented as smart contract wallets that support multiple owners. The SDK provides a wrapper around the low-level RPC methods used to interact with these accounts:
wallet_addSubAccount
: Creates a new Sub Accountwallet_connect
: Connects to an existing Sub Accountwallet_sendCalls
: Sends transactions from a Sub Account
Each Sub Account can have multiple owners identified by either their address or public key. When performing operations with a Sub Account, the appropriate owner is used to sign the transaction.
Requirements
- Coinbase Wallet SDK v4.4.0-canary or higher
- An app connected to an EVM-compatible chain