Prerequisites
Before you begin, you’ll need:
- A Crossmint API key (get one from the Crossmint Console)
- Ensure your API key has the following scopes enabled:
For client-side applications, use a client-side API key. For server-side applications, use a server-side API key.
Installation
Install the package
Install the Wallets SDK using your preferred package manager:npm install @crossmint/wallets-sdk
Import the SDK
Import the necessary functions from the SDK:import { CrossmintWallets, createCrossmint } from "@crossmint/wallets-sdk";
Initialize Crossmint
Create a Crossmint instance with your API key:const crossmint = createCrossmint({
apiKey: "<your-client-api-key>",
experimental_customAuth: {
jwt: "<your-jwt>", // Required for client-side
},
});
Create the Wallets SDK instance
Initialize the Wallets SDK:const crossmintWallets = CrossmintWallets.from(crossmint);
Create Your First Wallet
Client-side: Get or Create Wallet
On the client-side, use getOrCreateWallet to retrieve an existing wallet or create a new one:
const wallet = await crossmintWallets.getOrCreateWallet({
chain: "polygon",
signer: {
type: "email",
email: "[email protected]",
onAuthRequired: async (needsAuth, sendEmailWithOtp, verifyOtp, reject) => {
if (needsAuth) {
// Send OTP to user's email
await sendEmailWithOtp();
// Prompt the user for the OTP code
const otp = await promptUserForOtp(); // Your UI logic
// Verify the OTP
await verifyOtp(otp);
}
},
},
});
console.log(wallet.address); // e.g., "0x1234..."
Server-side: Create Wallet
On the server-side, use createWallet with an API key signer:
const wallet = await crossmintWallets.createWallet({
chain: "base",
signer: {
type: "api-key",
},
});
console.log(wallet.address);
Server-side: Get Existing Wallet
Retrieve an existing wallet by its address:
const wallet = await crossmintWallets.getWallet(
"0x1234567890abcdef1234567890abcdef12345678",
{
chain: "polygon",
signer: {
type: "api-key",
},
}
);
Signer Types
The SDK supports multiple signer types for authentication:
Email Signer
{
type: "email",
email: "[email protected]",
onAuthRequired: async (needsAuth, sendEmailWithOtp, verifyOtp, reject) => {
if (needsAuth) {
await sendEmailWithOtp();
const otp = await promptUserForOtp();
await verifyOtp(otp);
}
},
}
Phone Signer
{
type: "phone",
phone: "+1234567890",
onAuthRequired: async (needsAuth, sendSmsWithOtp, verifyOtp, reject) => {
if (needsAuth) {
await sendSmsWithOtp();
const otp = await promptUserForOtp();
await verifyOtp(otp);
}
},
}
Passkey Signer (EVM only)
{
type: "passkey",
name: "My Passkey",
onCreatePasskey: async (name) => {
// Your WebAuthn passkey creation logic
return {
id: "passkey-id",
publicKey: { x: "...", y: "..." },
};
},
onSignWithPasskey: async (message) => {
// Your WebAuthn signing logic
return {
signature: { r: "...", s: "..." },
metadata: { ... },
};
},
}
External Wallet Signer
{
type: "external-wallet",
address: "0x...",
provider: window.ethereum, // EIP-1193 provider
}
API Key Signer (Server-side only)
Chain Selection
Specify the blockchain when creating a wallet:
chain: "ethereum" | "polygon" | "base" | "arbitrum" | "optimism" | "avalanche" | ...
Wallet Properties
Once you have a Wallet instance, you can access:
wallet.address // The wallet's blockchain address
wallet.chain // The blockchain network (e.g., "polygon")
wallet.owner // The owner identifier (if applicable)
wallet.signer // The signer configuration
wallet.alias // Optional wallet alias
Next Steps
Wallet Operations
Learn how to check balances, send tokens, and view activity
EVM Wallets
Work with EVM chains and smart contracts
Solana Wallets
Build Solana applications
Delegated Signers
Add multiple signers to a wallet