11---
2- title : " Add Sub Accounts to OnchainKit "
2+ title : " Add Sub Accounts to Onchainkit/Minikit "
33---
44
5- import {GithubRepoCard } from " /snippets/GithubRepoCard.mdx" ;
5+ import { GithubRepoCard } from " /snippets/GithubRepoCard.mdx"
6+
7+
68
79This guide will show you how to add Sub Accounts to your existing [ OnchainKit] ( /builderkits/onchainkit/getting-started ) or [ MiniKit] ( /builderkits/minikit/quickstart ) project.
810
@@ -11,18 +13,34 @@ you can read more about it in the [Sub Accounts Intro Page](/identity/smart-wall
1113
1214Before you start, make sure you have checked the following guides:
1315
14- - [ OnchainKit Quickstart] ( /onchainkit/getting-started )
15- - [ OnchainKit Custom Providers] ( /onchainkit/config/supplemental-providers )
16- - [ Sub Accounts Intro Page] ( /smart-wallet/guides/sub-accounts )
16+ - [ OnchainKit Quickstart] ( /builderkits/onchainkit/getting-started )
17+ - [ MiniKit Quickstart] ( /builderkits/minikit/quickstart )
18+ - [ OnchainKit Custom Providers] ( /builderkits/onchainkit/config/supplemental-providers )
19+ - [ Sub Accounts Intro Page] ( /identity/smart-wallet/guides/sub-accounts )
20+
21+ <Warning >
22+ ** Smart Wallet compatibility with Mini Apps**
23+
24+ The Coinbase Wallet team is working on adding Smart Wallet support to Mini Apps.
25+
26+ For now, you can only use Sub Accounts with OnchainKit/MiniKit outside of the social feed.
27+ </Warning >
1728
1829## Skip ahead
1930
2031If you want to skip ahead and just get the final code, you can find it here:
2132
22- <GithubRepoCard title = " Sub Account OnchainKit Template Demo" githubUrl = " https://github.com/base/demos/tree/master/smart-wallet/sub-accounts-onchainkit" />
33+ <GithubRepoCard title = " Sub Account MiniKit Template Demo" githubUrl = " https://github.com/base/demos/tree/master/smart-wallet/sub-accounts-minikit" />
34+
35+ <Warning >
36+ ** About this codebase**
2337
38+ The codebase uses MiniKit, but the same code can be used for OnchainKit with minimal changes.
39+
40+ The difference is detailed in the [ Providers] ( #setting-up-the-onchainkitminikit-providers-config ) section.
41+ </Warning >
2442
25- ## Add Sub Accounts to your OnchainKit project
43+ ## Add Sub Accounts to your OnchainKit/MiniKit project
2644
2745### Override the default Coinbase Wallet SDK version
2846
@@ -31,7 +49,7 @@ Currently, Sub Accounts are only available in the Smart Wallet development envir
3149To override the default Coinbase Wallet SDK version, you can run the following command:
3250
3351``` bash
34- npm pkg set overrides. @coinbase/wallet-sdk= canary
52+ npm @coinbase/wallet-sdk@ canary install
3553```
3654
3755<Warning >
@@ -43,7 +61,6 @@ Make sure to delete the `node_modules` folder and `package-lock.json` file befor
4361rm -rf node_modules package-lock.json
4462npm install
4563```
46-
4764</Warning >
4865
4966<Check >
@@ -52,7 +69,6 @@ npm install
5269This is a temporary solution to get Sub Accounts working.
5370
5471Once the new version of the Coinbase Wallet SDK is released, you can remove this step.
55-
5672</Check >
5773
5874### Setting up the Wagmi config
@@ -112,7 +128,7 @@ Let's break down the key preference parameters:
112128- ` keysUrl ` : Points to the development environment for Smart Wallet testing
113129- ` options: 'smartWalletOnly' ` : Ensures only Smart Wallet mode is used
114130- ` enableAutoSubAccounts: true ` : When set to true, automatically creates a Sub Account at connection
115- - ` defaultSpendLimits ` : Configures Spend Permissions for Sub Account for a network (eg. Base Sepolia ` 84532 ` ), including:
131+ - ` defaultSpendLimits ` : Configures Spend Limits for Sub Account for a network (eg. Base Sepolia ` 84532 ` ), including:
116132
117133 - Token address (In this case, ` 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE ` represents the native ETH)
118134 - Allowance WEI amount (in Hex)
@@ -123,23 +139,62 @@ Let's break down the key preference parameters:
123139
124140Sub Accounts are currently only available in the Smart Wallet development environment.
125141To use this environment, you need to set the ` keysUrl ` to ` https://keys-dev.coinbase.com/connect ` in your configuration.
126-
127142</Warning >
128143
129144### Setting up the OnchainKit/MiniKit providers config
130145
131146Once the ` wagmi.ts ` file is updated, you can update your ` providers.tsx ` file to include the following:
132147
148+ <CodeGroup >
149+ ``` ts providers.tsx (MiniKit)
150+ " use client" ;
151+
152+ import { type ReactNode , useState } from " react" ;
153+ import { baseSepolia } from " wagmi/chains" ;
154+ import { QueryClient , QueryClientProvider } from " @tanstack/react-query" ;
155+ import { MiniKitProvider } from " @coinbase/onchainkit/minikit" ;
156+ import { type State , WagmiProvider } from " wagmi" ;
157+ import { getConfig } from " @/wagmi" ;
158+
159+ export function Providers(props : {
160+ children: ReactNode ;
161+ initialState? : State ;
162+ }) {
163+ const [config] = useState (() => getConfig ());
164+ const [queryClient] = useState (() => new QueryClient ());
165+
166+ return (
167+ < WagmiProvider config = {config } initialState = {props.initialState }>
168+ < QueryClientProvider client = {queryClient }>
169+ < MiniKitProvider
170+ apiKey = {process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY }
171+ chain = {baseSepolia }
172+ config = {{
173+ appearance : {
174+ mode : " auto" ,
175+ theme : " mini-app-theme" ,
176+ name : process .env .NEXT_PUBLIC_ONCHAINKIT_PROJECT_NAME ,
177+ logo : process .env .NEXT_PUBLIC_ICON_URL ,
178+ },
179+ }}
180+ >
181+ {props .children }
182+ < / MiniKitProvider >
183+ < / QueryClientProvider >
184+ < / WagmiProvider >
185+ );
186+ }
187+ ```
133188
134189``` ts providers.tsx (OnchainKit)
135190" use client" ;
136191
137- import { type ReactNode , useState } from " react"
138- import { baseSepolia } from " wagmi/chains"
139- import { QueryClient , QueryClientProvider } from " @tanstack/react-query"
140- import { MiniKitProvider } from " @coinbase/onchainkit/minikit"
141- import { type State , WagmiProvider } from " wagmi"
142- import { getConfig } from " @/wagmi"
192+ import { type ReactNode , useState } from " react" ;
193+ import { baseSepolia } from " wagmi/chains" ;
194+ import { QueryClient , QueryClientProvider } from " @tanstack/react-query" ;
195+ import { MiniKitProvider } from " @coinbase/onchainkit/minikit" ;
196+ import { type State , WagmiProvider } from " wagmi" ;
197+ import { getConfig } from " @/wagmi" ;
143198
144199export function Providers(props : {
145200 children: ReactNode ;
@@ -162,19 +217,28 @@ export function Providers(props: {
162217 );
163218}
164219```
220+ </CodeGroup >
221+
222+ <Check >
223+ ** For OnchainKit**
224+
225+ For OnchainKit, use ` OnchainKitProvider ` instead of ` MiniKitProvider ` as it's detailed in the
226+ [ OnchainKit Custom Providers page] ( /builderkits/onchainkit/config/supplemental-providers ) .
227+ </Check >
165228
166229## Run your app
167230
168231After installing the dependencies as described [ above] ( #override-the-default-coinbase-wallet-sdk-version ) ,
169232make sure your environment variables are up to date as per
170- the [ OnchainKit Quickstart] ( /builderkits/onchainkit/getting-started )
233+ the [ OnchainKit Quickstart] ( /builderkits/onchainkit/getting-started ) or
234+ [ MiniKit Quickstart] ( /builderkits/minikit/quickstart ) .
171235
172236Then, you can run the app with the following command:
173237
174238``` bash
175239npm run dev
176240```
177241
178- Congratulations! You've successfully added Sub Accounts to your OnchainKit project.
242+ Congratulations! You've successfully added Sub Accounts to your OnchainKit/MiniKit project.
179243
180244If you have any questions, join the _ #smart-wallet_ channel on [ Discord] ( https://discord.gg/cdp ) .
0 commit comments