Skip to content

Commit 89843f7

Browse files
authored
Merge branch 'master' into eb/update-agent-docs
2 parents 247e6bd + d20a55d commit 89843f7

File tree

19 files changed

+934
-128
lines changed

19 files changed

+934
-128
lines changed

docs/base-account/framework-integrations/cdp.mdx

Lines changed: 609 additions & 4 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: "Basenames"
3+
description: "Add support for Base names in your application using Wagmi and Viem"
4+
---
5+
6+
7+
8+
## Overview
9+
10+
Basenames are human-readable names for addresses on Base.
11+
They are built on top of the ENS protocol and comply with [ENSIP-19](https://docs.ens.domains/ensip/19/).
12+
To learn more about Basenames, check out the [Basenames FAQ](/base-account/basenames/basenames-faq).
13+
14+
This guide will show you how to add support for Basenames to your application using [Viem](https://viem.sh/).
15+
16+
## Usage
17+
18+
Use `getEnsName` to retrieve the primary ENS name for an address on Base:
19+
20+
```ts
21+
import { createPublicClient, http, toCoinType } from 'viem'
22+
import { base } from 'viem/chains'
23+
24+
const client = createPublicClient({
25+
chain: mainnet,
26+
transport: http(YOUR_PRIVATE_RPC_URL),
27+
})
28+
29+
const name = await client.getEnsName({
30+
address: '0x179A862703a4adfb29896552DF9e307980D19285',
31+
coinType: toCoinType(base.id),
32+
})
33+
```
34+
35+
<Tip>
36+
37+
It is necessary to use a private RPC provider (`YOUR_PRIVATE_RPC_URL`) due to the computational demands associated with some of the ENSIP-19 resolution steps.
38+
39+
</Tip>
40+
41+
<Warning>
42+
43+
There may be some latency between the initial registration of a Basename and the ability to resolve this name via ENSIP-19 due to the slow production of state proofs necessary for trustless resolution.
44+
</Warning>
45+
46+
[Learn more about getEnsName →](https://viem.sh/docs/ens/actions/getEnsName)

docs/base-account/improve-ux/sub-accounts.mdx

Lines changed: 90 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
---
22
title: 'Use Sub Accounts'
3-
description: 'Learn how to create and manage Sub Accounts using Base Account SDK'
3+
description: 'Learn how to create and use Sub Accounts using Base Account SDK'
44
---
55

66
import { GithubRepoCard } from "/snippets/GithubRepoCard.mdx"
77

88
## What are Sub Accounts?
99

10-
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.
11-
12-
To support Base Account with user experiences that need more developer control over wallet interactions, we've built Sub Accounts in conjunction with [ERC-7895](https://eip.tools/eip/7895), a new wallet RPC for creating hierarchical relationships between wallet accounts.
13-
14-
Sub Accounts allow you to provision wallet accounts that are directly embedded in your application for your users. You can control when a Sub Account is created and interact with them just as you would with another wallet via the wallet provider or popular web3 libraries like OnchainKit, wagmi, and viem.
10+
Sub Accounts allow you to provision app-specific wallet accounts for your users that are embedded directly in your application. Once created, you can interact with them just as you would with any other wallet via the wallet provider or popular onchain libraries like OnchainKit, wagmi, and viem.
1511

16-
These Sub Accounts are linked to the end user's Base Account through an onchain relationship. When combined with our [Spend Permission feature](/base-account/improve-ux/spend-permissions), this creates a powerful foundation for provisioning and funding app accounts securely, while giving you ample control over building the user experience that makes the most sense for your application.
12+
<Note>
13+
Looking for a full implementation? Jump to the [Complete Integration Example](/base-account/improve-ux/sub-accounts#complete-integration-example).
14+
</Note>
1715

1816
## Key Benefits
1917

20-
- **Seamless UX**: Reduce user friction by eliminating repeated signing prompts
21-
- **Developer Control**: Manage when and how Sub Accounts are created
22-
- **Secure Relationships**: Onchain linking between main account and sub accounts
23-
- **Spend Permissions**: Control what Sub Accounts can spend and when
24-
- **Easy Integration**: Works with existing web3 libraries and tools
18+
- **Frictionless transactions**: Eliminate repeated signing prompts for high frequency and agentic use cases or take full control of the transaction flow.
19+
- **No funding flows required**: Spend Permissions allow Sub Accounts to spend directly from the universal Base Account's balance.
20+
- **User control**: Users can manage all their sub accounts at [account.base.app](https://account.base.app).
2521

2622
<Note>
27-
If you would like to see a live demo of Sub Accounts in action, check out our [Sub Accounts Demo](https://sub-account-demo.com).
23+
If you would like to see a live demo of Sub Accounts in action, check out our [Sub Accounts Demo](https://sub-accounts-fc.vercel.app).
2824
</Note>
2925

3026
<Tip>
31-
**Pair with Spend Permissions**
27+
**Spend Permissions**
3228

33-
In order to make your UX more seamless, you can pair Sub Accounts with the
34-
[Spend Permissions](/base-account/improve-ux/spend-permissions)
35-
to make transactions on behalf of the user.
29+
Sub Accounts are optimized for use with Spend Permissions to allow your app to take advantage of the user's existing Base Account balances. See the [Spend Permissions](/base-account/improve-ux/spend-permissions) guide for more information about how they work.
3630
</Tip>
3731

3832
## Installation
@@ -57,11 +51,11 @@ bun add @base-org/account
5751
```
5852
</CodeGroup>
5953

60-
## Basic Setup
54+
## Using Sub Accounts
6155

6256
### Initialize the SDK
6357

64-
First, set up the Base Account SDK with Sub Account support:
58+
First, set up the Base Account SDK. Be sure to customize the `appName` and `appLogoUrl` to match your app as this will be displayed in the wallet connection popup and in the account.base.app dashboard. You can also customize the `appChainIds` to be the chains that your app supports.
6559

6660
```tsx
6761
import { createBaseAccountSDK, getCryptoKeyAccount } from '@base-org/account';
@@ -78,11 +72,16 @@ const sdk = createBaseAccountSDK({
7872
const provider = sdk.getProvider()
7973
```
8074

81-
## Using Sub Accounts
75+
### Create a Sub Account
8276

83-
### Create a New Sub Account
77+
<Tip>
78+
Make sure to authenticate the user with their Base Account before creating a Sub Account.
79+
For that, you can choose one of the following options:
80+
- Follow the [Authenticate users](/base-account/guides/authenticate-users) guide
81+
- Simply use `provider.request({ method: 'eth_requestAccounts' });` for a simple wallet connection
82+
</Tip>
8483

85-
Create a Sub Account for your application using the provider RPC method:
84+
Create a Sub Account for your application using the provider's [wallet_addSubAccount](/base-account/reference/core/provider-rpc-methods/wallet_addSubAccount) RPC method. When no `publicKey` parameter is provided, a non-extractable browser CryptoKey is generated and used to sign on behalf of the Sub Account.
8685

8786
```tsx
8887
// Create sub account
@@ -100,20 +99,9 @@ const subAccount = await provider.request({
10099
console.log('Sub Account created:', subAccount.address);
101100
```
102101

103-
<Tip>
104-
**Tip:**
105-
106-
Make sure to authenticate the user with their universal account before creating a Sub Account.
107-
For that, you can choose one of the following options:
108-
- Follow the [Authenticate users](/base-account/guides/authenticate-users) guide
109-
- Simply use `provider.request({ method: 'eth_requestAccounts' });` for a simple wallet connection
110-
111-
</Tip>
112-
113-
Create a Sub Account using the SDK convenience method:
102+
Alternatively, you can use the SDK convenience method:
114103

115104
```tsx
116-
// Create new sub account
117105
const subAccount = await sdk.subAccount.create();
118106

119107
console.log('Sub Account created:', subAccount.address);
@@ -125,38 +113,9 @@ This is what the user will see when prompted to create a Sub Account:
125113
<img src="/images/base-account/SubAccountCreation.png" alt="Sub Account Creation Flow" style={{ width: '300px', height: 'auto' }} />
126114
</div>
127115

128-
### Import an existing Sub Account
129-
130-
If you already have a deployed Smart Contract Account, you can import it as a Sub Account using the provider RPC method:
131-
132-
```tsx
133-
const subAccount = await provider.request({
134-
method: 'wallet_addSubAccount',
135-
params: [
136-
{
137-
account: {
138-
type: 'deployed',
139-
address: '0xYourSmartContractAccountAddress',
140-
chainId: 8453 // the chain the account is deployed on
141-
},
142-
}
143-
],
144-
});
145-
146-
console.log('Sub Account added:', subAccount.address);
147-
```
148-
149-
<Note>
150-
151-
Before the Sub Account is imported, you will need to add the Base Account address as an owner of the Sub Account. This currently needs to be done manually
152-
by calling the [`addOwnerAddress`](https://github.com/coinbase/smart-wallet/blob/a8c6456f3a6d5d2dea08d6336b3be13395cacd42/src/MultiOwnable.sol#L101) or [`addOwnerPublicKey`](https://github.com/coinbase/smart-wallet/blob/a8c6456f3a6d5d2dea08d6336b3be13395cacd42/src/MultiOwnable.sol#L109) functions on the Smart Contract of the Sub Account that was imported and setting the Base Account address as the owner.
153-
154-
Additionally, only Coinbase Smart Wallet contracts are currently supported for importing as a Sub Account into your Base Account.
155-
</Note>
156-
157116
### Get Existing Sub Account
158117

159-
Retrieve an existing Sub Account using the provider RPC method:
118+
Retrieve an existing Sub Account using the provider's [wallet_getSubAccounts](/base-account/reference/core/provider-rpc-methods/wallet_getSubAccounts) RPC method. This will return the Sub Account associated with the app's domain and is useful to check if a Sub Account already exists for the user to determine if one needs to be created.
160119

161120
```tsx
162121
// Get the universal account
@@ -181,10 +140,9 @@ if (subAccount) {
181140
}
182141
```
183142

184-
Get the Sub Account associated with the current app using the SDK convenience method:
143+
Alternatively, you can use the SDK convenience method:
185144

186145
```tsx
187-
// Get sub account
188146
const subAccount = await sdk.subAccount.get();
189147

190148
console.log('Sub Account:', subAccount);
@@ -193,29 +151,32 @@ console.log('Sub Account:', subAccount);
193151

194152
To send transactions from the connected sub account you can use EIP-5792 `wallet_sendCalls` or `eth_sendTransaction`. You need to specify the `from` parameter to be the sub account address.
195153

196-
197-
198154
<Tip>
199-
**Tip:**
155+
When the Sub Account is connected, it is the second account in the array returned by `eth_requestAccounts` or `eth_accounts`. `wallet_addSubAccount` needs to be called in each session before the Sub Account can be used. It will not trigger a new Sub Account creation if one already exists.
200156

201-
When the sub account is connected, it is the second account in the array returned by `eth_requestAccounts` or `eth_accounts`.
157+
If you are using `mode: 'auto'`, the Sub Account will be the first account in the array.
202158
</Tip>
203159

160+
First, get all the accounts that are available, of which the sub account will be the second account:
204161

205162
```tsx
206-
// Get the sub account address
207163
const [universalAddress, subAccountAddress] = await provider.request({
208164
method: "eth_requestAccounts", // or "eth_accounts" if already connected
209165
params: []
210166
})
167+
```
168+
169+
Then, send the transaction from the sub account:
170+
171+
**`wallet_sendCalls`**
211172

212-
// wallet_sendCalls
173+
```tsx
213174
const callsId = await provider.request({
214175
method: 'wallet_sendCalls',
215176
params: [{
216177
version: "2.0",
217178
atomicRequired: true,
218-
from: subAccountAddress,
179+
from: subAccountAddress, // Specify the sub account address
219180
calls: [{
220181
to: '0x...',
221182
data: '0x...',
@@ -229,13 +190,15 @@ const callsId = await provider.request({
229190
})
230191

231192
console.log('Calls sent:', callsId);
193+
```
232194

195+
**`eth_sendTransaction`**
233196

234-
// eth_sendTransaction
197+
```tsx
235198
const tx = await provider.request({
236199
method: 'eth_sendTransaction',
237200
params: [{
238-
from: subAccountAddress,
201+
from: subAccountAddress, // Specify the sub account address
239202
to: '0x...',
240203
data: '0x...',
241204
value: '0x...',
@@ -245,12 +208,47 @@ const tx = await provider.request({
245208
console.log('Transaction sent:', tx);
246209
```
247210

211+
We recommend using `wallet_sendCalls` in conjunction with a paymaster to ensure the best user experience. See the [Paymasters](/base-account/improve-ux/sponsor-gas/paymasters) guide for more information.
212+
213+
## Advanced Usage
214+
215+
### Import an existing account
216+
217+
If you already have a deployed Smart Contract Account and would like to turn it into a Sub Account of the connected Base Account, you can import it as a Sub Account using the provider RPC method:
218+
219+
```tsx
220+
const subAccount = await provider.request({
221+
method: 'wallet_addSubAccount',
222+
params: [
223+
{
224+
account: {
225+
type: 'deployed',
226+
address: '0xYourSmartContractAccountAddress',
227+
chainId: 8453 // the chain the account is deployed on
228+
},
229+
}
230+
],
231+
});
232+
233+
console.log('Sub Account added:', subAccount.address);
234+
```
235+
236+
<Note>
237+
238+
Before the Sub Account is imported, you will need to add the Base Account address as an owner of the Sub Account. This currently needs to be done manually
239+
by calling the [`addOwnerAddress`](https://github.com/coinbase/smart-wallet/blob/a8c6456f3a6d5d2dea08d6336b3be13395cacd42/src/MultiOwnable.sol#L101) or [`addOwnerPublicKey`](https://github.com/coinbase/smart-wallet/blob/a8c6456f3a6d5d2dea08d6336b3be13395cacd42/src/MultiOwnable.sol#L109) functions on the Smart Contract of the Sub Account that was imported and setting the Base Account address as the owner.
240+
241+
Additionally, only Coinbase Smart Wallet contracts are currently supported for importing as a Sub Account into your Base Account.
242+
243+
The Coinbase Smart Wallet contract ABI can be found on [GitHub](https://github.com/base/account-sdk/blob/master/packages/account-sdk/src/sign/base-account/utils/constants.ts#L8).
244+
</Note>
245+
246+
248247
### Add Owner Account
249248

250-
Add an owner to a Sub Account:
249+
Sub Accounts automatically detect when an ownership update is needed when a signature is required and will prompt the user to approve the update before signing. However, you can also add an owner to a Sub Account manually using the SDK convenience method:
251250

252251
```tsx
253-
// Add owner account
254252
const ownerAccount = await sdk.subAccount.addOwner({
255253
address: subAccount?.address,
256254
publicKey: cryptoAccount?.account?.publicKey,
@@ -260,6 +258,14 @@ const ownerAccount = await sdk.subAccount.addOwner({
260258
console.log('Owner added to Sub Account');
261259
```
262260

261+
This generates a transaction to call the `addOwnerAddress` or `addOwnerPublicKey` functions on the Sub Account's smart contract to add the owner.
262+
263+
<Note>
264+
Ownership changes are expected if the user signs in to your app on a new device or browser.
265+
266+
Ensure you do not lose your app's Sub Account signer keys when using the SDK on the server (e.g. Node.js) as updating the owner requires a signature from the user, which cannot be requested from server contexts.
267+
</Note>
268+
263269
## Auto Spend Permissions
264270

265271
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.
@@ -301,6 +307,13 @@ Spend permission requests are limited to the first token when multiple transfers
301307
</Warning>
302308

303309

310+
## Technical Details
311+
312+
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.
313+
314+
To support Base Account with user experiences that need more developer control over wallet interactions, we've built Sub Accounts in conjunction with [ERC-7895](https://eip.tools/eip/7895), a new wallet RPC for creating hierarchical relationships between wallet accounts.
315+
316+
These Sub Accounts are linked to the end user's Base Account through an onchain relationship. When combined with our [Spend Permission feature](/base-account/improve-ux/spend-permissions), this creates a powerful foundation for provisioning and funding app accounts securely, while giving you ample control over building the user experience that makes the most sense for your application.
304317

305318

306319
## Complete Integration Example
@@ -345,7 +358,6 @@ export default function SubAccountDemo() {
345358
try {
346359
const sdkInstance = createBaseAccountSDK({
347360
appName: "Sub Account Demo",
348-
appLogoUrl: "https://base.org/logo.png",
349361
appChainIds: [baseSepolia.id],
350362
});
351363

docs/base-chain/tools/onramps.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ description: Documentation for fiat-to-crypto onramps for the Base network.
1919

2020
[Ramp](https://ramp.network/) is an onramp and offramp that empowers users to buy & sell crypto inside your app. Ramp supports 40+ fiat currencies and 90+ crypto assets, including ETH on Base.
2121

22+
## Thirdweb
23+
24+
[Thirdweb Payments](https://thirdweb.com/payments) is an all-in-one crypto payment solution allowing you to onramp, bridge, and swap over [3,200+ currencies](https://thirdweb.com/tokens) on over [85+ chains](https://thirdweb.com/chainlist?service=pay).
25+
2226
## Transak
2327

2428
[Transak](https://transak.com/) is a developer integration toolkit to let users buy/sell crypto in any app, website or web plugin. It is available across 170 cryptocurrencies on 75+ blockchains, including ETH on Base.

0 commit comments

Comments
 (0)