Privy
How to integrate your existing Privy authentication and wallets with Crossmint
Overview
This guide shows how to integrate Privy authentication and embedded wallets with Crossmint Smart Wallets. Users authenticate with Privy, and their Privy embedded wallet serves as a signer for a Crossmint Smart Wallet.
Create an API Key
The first step for integrating Privy authentication is to obtain a client-side 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.
Configure Privy Authentication for your API Key
After the key is generated, you need to set it to require Privy auth tokens for authorization.
- Go to the Privy dashboard at https://dashboard.privy.io/
- Select an existing project or create a new one
When you’re ready to move to production/mainnet with Privy, you will need to complete the “Upgrade to production” steps in the Privy dashboard (Settings > Basic > Application state).
- 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
Install Required Dependencies
Install the Crossmint React UI SDK and shadcn UI components:
Then, set up shadcn UI components:
Install the button and card components:
Configure Environment Variables
Add your Crossmint client-side API key and Privy App ID to your environment file:
Create the Provider Components
First, create a CrossmintPrivyProvider component that will wrap your application:
Now create a custom hook that connects Privy with Crossmint:
Update Your Layout
Update your app’s layout to use the CrossmintPrivyProvider:
Create UI Components
Create a component that uses the Privy connector and displays wallet information:
Create Your Main Page
Create your main page that uses the WalletCard component:
Launch and Test
- Start your development server:
- Visit http://localhost:3000 in your browser
- Click the “Log In with Privy” button to start the authentication flow
- Follow the prompts to authenticate using Privy
- Once logged in, you should see both your Privy embedded wallet address and your Crossmint Smart Wallet address
How It Works
The integration between Privy and Crossmint involves these key components:
-
Authentication Flow:
- User logs in using Privy’s authentication
- Privy creates an embedded wallet for the user
- The Crossmint SDK uses the JWT from Privy to authenticate with Crossmint
-
Wallet Creation:
- The
usePrivyConnector
hook finds the Privy embedded wallet - It retrieves the Ethereum provider from the Privy wallet to use as a signer
- It creates a Crossmint Smart Wallet using the Privy wallet as the signer
- The
-
Key Benefits:
- Users leverage their existing Privy authentication
- No new key management required
- The Privy embedded wallet serves as a signer for the Crossmint Smart Wallet
- Cross-chain support through Crossmint’s infrastructure
Learn More
For more information on working with Crossmint Smart Wallets, check out these resources:
Was this page helpful?