You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/base-account/improve-ux/sub-accounts.mdx
+43-16Lines changed: 43 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,32 @@ bun add @base-org/account
51
51
```
52
52
</CodeGroup>
53
53
54
+
## Quickstart
55
+
56
+
The fastest way to adopt Sub Accounts is to set `creation` to `on-connect` and `defaultAccount` to `sub` in the SDK configuration.
57
+
58
+
```tsx
59
+
const sdk =createBaseAccountSDK({
60
+
// ...
61
+
subAccounts: {
62
+
creation: 'on-connect',
63
+
defaultAccount: 'sub',
64
+
}
65
+
});
66
+
```
67
+
68
+
This will automatically create a Sub Account for the user when they connect their Base Account and transactions will automatically be sent from the Sub Account unless you specify the `from` parameter in your transaction request to be the universal account address. Spend Permissions will also be automatically requested for the Sub Account as your app needs them.
69
+
70
+
This is what the user will see when they connect their Base Account and automatic Sub Accounts are enabled:
We recommend using a [Paymaster](/base-account/improve-ux/sponsor-gas/paymasters) to sponsor gas to ensure the best user experience when integrating Sub Accounts. You can set a paymaster to be used for all transactions by configuring the `paymasterUrls` parameter in the SDK configuration. See the [createBaseAccount](/base-account/reference/core/createBaseAccount#param-paymaster-urls) reference for more information.
78
+
</Tip>
79
+
54
80
## Using Sub Accounts
55
81
56
82
### Initialize the SDK
@@ -270,22 +296,7 @@ Ensure you do not lose your app's Sub Account signer keys when using the SDK on
270
296
271
297
Auto Spend Permissions allows Sub Accounts to access funds from their parent Base Account when transaction balances are insufficient. This feature can also establish ongoing spend permissions, enabling future transactions to execute without user approval prompts, reducing friction in your app's transaction flow.
272
298
273
-
### Configuration
274
-
275
-
Auto Spend Permissions is only available in SDK version `2.1.0` or later. This feature is **enabled by default** when using Sub Accounts.
276
-
277
-
To disable Auto Spend Permissions when using Sub Accounts, set `unstable_enableAutoSpendPermissions` to `false` in your SDK configuration:
278
-
279
-
```tsx
280
-
const sdk =createBaseAccountSDK({
281
-
appName: 'Base Account SDK Demo',
282
-
appLogoUrl: 'https://base.org/logo.png',
283
-
appChainIds: [base.id],
284
-
subAccounts: {
285
-
unstable_enableAutoSpendPermissions: false, // Disable auto spend permissions
286
-
}
287
-
});
288
-
```
299
+
This feature is **enabled by default** when using Sub Accounts.
289
300
290
301
### How it works
291
302
@@ -307,6 +318,22 @@ Spend permission requests are limited to the first token when multiple transfers
307
318
</Warning>
308
319
309
320
321
+
### Configuration
322
+
323
+
If your users' Sub Accounts will be funded manually, you can disable Auto Spend Permissions by setting `funding` to `manual` in your SDK configuration:
324
+
325
+
```tsx
326
+
const sdk =createBaseAccountSDK({
327
+
appName: 'Base Account SDK Demo',
328
+
appLogoUrl: 'https://base.org/logo.png',
329
+
appChainIds: [base.id],
330
+
subAccounts: {
331
+
funding: 'manual', // Disable auto spend permissions
332
+
}
333
+
});
334
+
```
335
+
336
+
310
337
## Technical Details
311
338
312
339
Base Account's self-custodial design requires a user passkey prompt for each wallet interaction, such as transactions or message signing. While this ensures user awareness and approval of every wallet interaction, it can impact user experience in applications requiring frequent wallet interactions.
Controls when sub-accounts are created. Defaults to `'manual'`.
64
+
65
+
-`'on-connect'`: Automatically creates a sub-account when connecting to the wallet (automatically injects `addSubAccount` capability to `wallet_connect`)
66
+
-`'manual'`: Requires explicit `wallet_addSubAccount` call to create a sub-account
Controls how sub-accounts are funded. Defaults to `'spend-permissions'`.
78
+
79
+
-`'spend-permissions'`: Routes through universal account if no spend permissions exist, handles insufficient balance errors automatically. Learn more in [Auto Spend Permissions](/base-account/improve-ux/sub-accounts#auto-spend-permissions)
80
+
-`'manual'`: Direct execution from sub-account without automatic fallbacks
When <code>true</code> (default), enables Auto Spend Permissions for sub-accounts. This allows automatic transfers from the user's Base Account to the sub-account when funds are missing and attempts background transactions using existing spend permissions. Set to <code>false</code> to disable this behavior. Learn more in [Auto Spend Permissions](/base-account/improve-ux/sub-accounts#auto-spend-permissions).
0 commit comments