Getting Started with Privy
Let's get started with a basic example using Privy
Pre-requisites
1. Set Up Authorization Keys
What is an authorization key?
The authorization key is a user created by you, the client application, for the Enclave team, that allows us to issue transaction policies that enforce resource locks on users that wish to enable Magicspend++.
You can create an authorization key on the Privy dashboard by following the steps mentioned here.
Once you have created the authorization key, share the all key details with the Enclave team to enable integration. Also note down it's public key and API key name, these values are required for the next step.
2. Creating Users and Wallets with Key Quorums
Modify the existing user creation logic in your onboarding flow to provision a wallet with a key quorum that includes both the end user and the authorization key created in the previous step.
The key quorum structure is such that each unique user has a wallet owned by a key quorum with 2 members: the end user and the authorization key that issues policies on the user's wallet.
Given below is some sample code that can be used as reference:
Creating a wallet with authorization key
import { usePrivy } from '@privy-io/react-auth';
const WalletComponent = () => {
const { getAccessToken, authenticated } = usePrivy();
const authPublicKey = process.env.NEXT_PUBLIC_ENCLAVE_AUTH_PUBLIC_KEY!;
if (!authPublicKey) {
console.log('⚠️ Authorization key not found in environment variables, skipping');
return;
}
const createWalletWithQuorum = async (chainType: 'ethereum' | 'solana') => {
const token = await getAccessToken();
const response = await fetch('/api/wallets/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({ chainType }),
});
const result = await response.json();
return result.wallet;
};
};Server-side implementation
Next let's see how we can fetch a quote
Fetching a quoteLast updated