Smart Wallets (browser)
Set up a Smart Wallet in 5 minutes
In this quickstart you will create a Next.js web app with smart wallets embedded. At the end of the tutorial, you will have learned how to:
- Use Crossmint to log users into your app
- Create a smart wallet (in an EVM testnet) for your users when they sign up
- Set up a passkey (e.g. touch id / face id) to control the wallet
- Retrieve the wallet address
Integration Steps
1. Create and Configure a Crossmint Project
To get started, create a developer account in the Crossmint Staging Console. Open that link, sign in, and accept the dialog to continue.
Then, navigate to project Settings > General, and change the wallet type to Smart Wallets
.
2. Get an API Key
Navigate to the "Integrate" section on the left navigation bar, and ensure you're on the "API Keys" tab.
Within the Client-side keys section, click the "Create new key" button in the top right.
On the authorized origins section, enter http://localhost:3000
and click "Add origin".
Next, check the scopes labeled wallets.create
, wallets.read
, users.create
.
Check the "JWT Auth" box
Finally, create your key and save it for subsequent steps.
3. Project Set Up
Create a new Next.js application
Use the create-next-app
package to get started:
If you see this message enter y
and Enter
to proceed:
Name your app `my-first-smart-wallet-app` and accept the default options
Change into the directory created in previous steps
Install the Crossmint React SDK
Add a new file named `.env.local` to root directory of your project
Set your environment variables by adding your client-side API secret from Step 1.
Prepare wallet page
Open app/page.tsx
, delete the contents, and leave a minimal page, for next steps.
4. Set Up User Auth
Before creating wallets for your users, you need to implement a login system. In this quickstart, we’ll demonstrate this using Crossmint Auth, a fully managed authentication service provided by Crossmint. However, you can use any authentication system of your choice.
Configure Crossmint Auth in Layout
To configure auth, we need to create a new file for our Crossmint providers and then import it into our root layout.
Create a new file app/providers/Providers.tsx
and add the following code:
Now, open app/layout.tsx
and update it to use the new Providers component:
This setup encapsulates the Crossmint providers in a separate file, making your code more modular. The Providers
component wraps your application with both CrossmintProvider
and CrossmintAuthProvider
, configuring the
Crossmint SDK and auth. Note that we’re setting wallets to operate by default in the polygon-amoy
testnet.
Add login and logout functionality
Now, add the following import to the top of your page.tsx
file, below the "use client";
directive:
Next, declare a component that handles the login and logout functionality. This component uses the useAuth
hook to
manage authentication state and provides buttons for logging in and out.
Finally, add the AuthButton
component inside your Home
component.
5. Create and Use the Wallet
Finally, we are ready to create our first user smart wallet, which will use passkeys as a signer.
Display wallet address
Now, let’s display the wallet address in our UI. We will use the useWallet
hook from the
@crossmint/client-sdk-react-ui
package to fetch the wallet details.
First, import the useWallet
hook in your page.tsx
file:
Next, declare a Wallet
component that will use this hook to display the wallet address:
Finally, add the Wallet
component to your Home
component, replacing the TO-DO placeholder:
The Wallet
component will display the wallet address if it’s loaded, show a loading message while the wallet is
being fetched, and display an error message if there’s an error.
Run the React App and Log In
To see the authentication dialog and continue to see the results, follow these steps:
- From the root directory of your project, run the following command:
- The command line will output a localhost url and port, such as
http://localhost:3000
. Open it.
If the port is different than 3000, edit the API key from step 2 to add the right port and URL in the Crossmint console
- Click on the “Log In” button to open the authentication dialog.
- Follow the prompts to log in using your Passkey.
- Once logged in, you will see the wallet created and displayed using the
Wallet
component.
At the end of this process, you will be signed in with a wallet created using Passkeys!
6. Next steps
And that’s it! You now have created an embedded Smart Wallet. Next you can learn how to perform actions with your wallet with the SDK, like signing messages, transactions, and more.