Crossmint Smart Wallets are compatible with Dynamic.xyz. This guide explains how to automatically attach a Smart Wallet to your dynamic embedded wallet, to enable smart wallet features such as gasless transactions, modules, chain abstracted balance, and more, while continuing to leverage dynamic for authentication and key custody.

Create an API Key

The first step for integrating 3rd party authentication into your project with Crossmint is to obtain a client-side API key. You can find more info for creating a client-side API key here.

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.

Use Dynamic.xyz for API Key Authentication

After the key is generated, you need to set it to require dynamic.xyz auth tokens for authorization.

To begin, go to the Dynamic dashboard at https://app.dynamic.xyz/.

Once logged in, select an existing project or create a new one.

You need to make sure you’re using live keys for mainnets and sandbox keys for staging/testnets.
screenshot showing where to select Dynamic project

Then expand the “Developers” section in the left-hand navigation and select “SDK and API Keys” to find your Dynamic Environment ID.

screenshot showing where to find Dynamic Environment ID

Copy the Dynamic Environment ID and return to the Crossmint developer console. Within the JWT authentication section, select “3P Auth providers” option, and then select Dynamic. Add your Environment ID and save changes.

screenshot showing where to save Dynamic Environment ID in Crossmint developer console

You now have a properly configured client-side API key to use. Continue on to learn how to add Crossmint Smart Wallets to your application that uses Dynamic for authentication.

Integration Guide

To integrate Crossmint Smart Wallets with Dynamic as the auth provider you need to begin by configuring the environment ID you located in the above steps to work with the chain you want to create the smart wallet on. With the same project selected as above select the “Chains and Networks” option in the left-hand navigation.

Then click the EVM option to reveal a drawer where you can toggle chain support on and off.

screenshot showing where to open Dynamic chains configuration pane

Enable the desired chain for smart wallet support. In this guide, the example will be using polygon-amoy.

screenshot showing where to select polygon-amoy chain in Dynamic.xyz configuration pane

With the Dynamic environment ID configuration taken care of, you can now move on to integrating the smart wallets into your app.

Install the Crossmint React UI SDK:

pnpm i @crossmint/client-sdk-react-ui

Add your Crossmint client-side API key to your environment file:

.env.local
NEXT_PUBLIC_DYNAMIC_ENV_ID=_YOUR_DYNAMIC_ENV_ID_
NEXT_PUBLIC_CROSSMINT_API_KEY=_YOUR_CROSSMINT_API_KEY_

The providers.tsx code snippet below is adapted from the demo repository provided by Dynamic. You can view that repo here: https://github.com/dynamic-labs/nextjs-viem-wagmi.

Add a new file with the contents of the crossmint-wrapper.tsx tab to your app and then update your providers.tsx file as demonstrated.

A Smart Wallet will automatically be created or fetched for logged-in users. The key detail that leads to this behavior is the config.createOnLogin setting, which is passed to the CrossmintWalletProvider. By setting this to all-users a wallet is created automatically. If a wallet was previously created for the user the same one will be returned.

Elsewhere in your app you can import the useWallet hook from the SDK to access the smart wallet object and perform actions with the wallet.

import { useWallet } from "@crossmint/client-sdk-react-ui"

// This component must be instantiated as a descendent of a CrossmintWalletProvider
export default function MyComponent() {
  const { wallet, status } = useWallet();

   if (status === "in-progress") {
    return <div>loading</div>
  }

  console.log("status:", status);
  console.log("wallet:", wallet?.address);

  return <div>{ wallet?.address }</div>;
}