Project Setup (Wagmi)
Set up a NextJS project with Smart Wallet integration
In this section, we’ll set up a NextJS project using Wagmi hooks and configure it to work with Smart Wallet.
What you’ll achieve
By the end of this guide, you will:
- Set up a NextJS+Wagmi project and configure it to work with Smart Wallet
- Create a Wagmi config to use Sub Accounts in conjunction with Spend Permissions
Skip ahead
If you want to skip ahead and just get the final code, you can find it here:
Creating a New Project
We’ll be using a Wagmi template to bootstrap this project.
First, create a new Wagmi project:
Select the following options:
Navigate into the project directory:
Let’s override the default @coinbase/wallet-sdk
version with the latest canary version:
Override before installing
Sub Accounts are currently only available in the Smart Wallet development environment (Canary).
Make sure to override the @coinbase/wallet-sdk
version BEFORE installing the packages.
Install packages
Setting up the Wagmi config
After running these commands, it is time to set up the Wagmi config.
Let’s break down the key preference parameters:
-
keysUrl
: Points to the development environment for Smart Wallet testing -
options: 'smartWalletOnly'
: Ensures only Smart Wallet mode is used -
enableAutoSubAccounts: true
: When set to true, automatically creates a Sub Account at connection -
defaultSpendLimits
: Configures Spend Permissions for Sub Account for a network (eg. Base Sepolia84532
), including:- Token address (In this case,
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
represents the native ETH) - Allowance WEI amount (in Hex)
- Time period for the allowance (in seconds, e.g., 86400 for 24 hours)
- Token address (In this case,
About keysUrl
Sub Accounts are currently only available in the Smart Wallet development environment.
To use this environment, you need to set the keysUrl
to https://keys-dev.coinbase.com/connect
in your configuration.
Creating the Home Page
Update your main page (app/page.tsx
) to include wallet connection functionality:
Testing the Setup
- Start your development server:
- Open your browser and navigate to
http://localhost:3000
. - Click the “Sign in with Smart Wallet” button to connect your Smart Wallet.
- You should be prompted to create a Sub Account as shown below.
Now that you have the basic setup complete, you’re ready to start using Sub Accounts! Continue to the next section to learn how to send transactions using your Sub Account.
Next Steps
In the next section, we’ll cover Using Sub Accounts - how to sign messages and send transactions with your Sub Account.
Additional Resources
- You can take a look at the final code in the Sub Account Starter Template Demo
- You can reach out to us on the #smart-wallet channel on Discord if you have any questions or feedback