Privy
How to integrate your existing Privy authentication and wallets with Crossmint
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 Privy for API Key Authentication
After the key is generated, you need to set it to require Privy auth tokens for authorization.
To begin, go to the Privy dashboard at https://dashboard.privy.io/.
Once logged in, select an existing project or create a new one.
Then select the “Settings” link from left-hand navigation to find your Privy App ID.
Copy the Privy App ID and return to the Crossmint developer console. Within the JWT authentication section, select “3P Auth providers” option, and then select Privy. Add your App ID and click the “Save JWT auth settings” button.
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 Privy for authentication.
Integration Guide
Install the Crossmint React UI SDK:
Add your Crossmint client-side API key to your environment file:
The layout.tsx
code snippet below is adapted from the quickstart repository provided by Privy. You can view that repo here: https://github.com/privy-io/create-next-app.
layout.tsx
sample code is adapted from the app-router
branch of the Privy quickstart repository.Add a new file with the contents of the CrossmintWrapper.tsx
tab to your app and update the layout.tsx
file as demonstrated.
Use Privy Embedded Wallet as the Signer
Applications that already use embedded wallets from Privy can easily add a Crossmint Smart Wallet that uses the embedded wallet as the signer.
Add a new directory to your /app
folder named smart-wallet
and create a new page.tsx
file within it. Then copy the contents of the code sample below to create a smart wallet for the logged in user.
The example above is specifying a Privy embedded wallet as the signer. This is happening in the useEffect
hook where the wallets are filtered by walletClientType
=== “privy”.
If you want to use a different connected wallet as the signer you’d pass it to the getOrCreateWallet
function instead. The wallets
object returned from the useWallets
call will return an array of connected wallets in order of how recently they were connected.
Refer to this docs page for Privy useWallets hook for more info on selecting a specific wallet.