@joai/warps-wallet-privy
v1.0.0-beta.9
Published
Privy wallet provider for multiple chains - Node.js compatible, no React dependencies
Readme
@joai/warps-wallet-privy
Privy wallet provider for Warps SDK. This package enables you to use Privy wallets with the Warps SDK across multiple blockchain networks. Designed for Node.js environments - no React dependencies required.
Installation
npm install @joai/warps-wallet-privyPrerequisites
@joai/warpscore package installed- Privy SDK installed and configured (
@privy-io/server-sdkfor Node.js)
Usage
Node.js Usage
Use Privy's server SDK to create a client:
import { PrivyClient } from '@privy-io/server-sdk'
import { PrivyWalletProvider } from '@joai/warps-wallet-privy'
import { WarpClient } from '@joai/warps'
import { getEvmAdapter } from '@joai/warps-adapter-evm'
const privyServerClient = new PrivyClient(process.env.PRIVY_APP_ID, process.env.PRIVY_APP_SECRET)
const privyClient = {
getAddress: async () => {
const user = await privyServerClient.getUser(userId)
return user.wallet?.address || null
},
signTransaction: async (tx: any) => {
return await privyServerClient.signTransaction(userId, tx)
},
signMessage: async (message: string) => {
return await privyServerClient.signMessage(userId, message)
},
}
const config = {
env: 'mainnet',
walletProviders: {
ethereum: () => new PrivyWalletProvider({ privyClient }),
},
}
const client = new WarpClient(config, [getEvmAdapter(config)])
// Use the client as normal
const wallet = client.getWallet('ethereum')
const address = await wallet.getAddress()Browser/React Usage (Optional)
If you're using Privy in a React application, you can create a client adapter:
import { PrivyWalletProvider } from '@joai/warps-wallet-privy'
import { WarpClient } from '@joai/warps'
import { getEvmAdapter } from '@joai/warps-adapter-evm'
// Create a Privy client adapter from your React Privy instance
const privyClient = {
getAddress: async () => {
// Get address from your Privy instance
return privyInstance.user?.wallet?.address || null
},
signTransaction: async (tx: any) => {
// Sign transaction using your Privy instance
return await privyInstance.user?.wallet?.signTransaction(tx)
},
signMessage: async (message: string) => {
// Sign message using your Privy instance
return await privyInstance.user?.wallet?.signMessage(message)
},
}
const config = {
env: 'mainnet',
walletProviders: {
ethereum: () => new PrivyWalletProvider({ privyClient }),
},
}
const client = new WarpClient(config, [getEvmAdapter(config)])With Multiple Chains
The Privy wallet provider supports multiple chains. You can configure it for different chains:
const privyClient = {
getAddress: async () => /* ... */,
signTransaction: async (tx: any) => /* ... */,
signMessage: async (message: string) => /* ... */,
}
const config = {
env: 'mainnet',
walletProviders: {
ethereum: () => new PrivyWalletProvider({ privyClient }),
solana: () => new PrivyWalletProvider({ privyClient }),
},
}
const client = new WarpClient(config, [
getEvmAdapter(config),
getSolanaAdapter(config),
])API
Implements the WalletProvider interface from @joai/warps.
Constructor:
new PrivyWalletProvider(config: PrivyWalletProviderConfig)Parameters:
config.privyClient: The Privy client interfacegetAddress(): Promise<string | null>- Get the wallet addresssignTransaction(tx: any): Promise<string>- Sign a transactionsignMessage(message: string): Promise<string>- Sign a message
config.address(optional): Fallback address if client doesn't provide one
Methods:
getAddress(): Promise<string | null>- Get the wallet addressgetPublicKey(): Promise<string | null>- Get the public key (returns null for Privy)signTransaction(tx: any): Promise<any>- Sign a transactionsignMessage(message: string): Promise<string>- Sign a message
Supported Chains
The Privy wallet provider works with any chain that Privy supports, including:
- Ethereum and EVM-compatible chains
- Solana
- And other chains supported by Privy
Notes
- Node.js-first design: This package has no React dependencies and is designed to work in Node.js environments
- You need to provide a Privy client adapter that implements the
PrivyClientinterface - Public key is not available through Privy, so
getPublicKey()always returnsnull - The client adapter should handle authentication and wallet availability checks
- For React applications, create a client adapter that wraps your Privy React hooks
