Use Privy with ZeroDev
Privy offers a seamless user onboarding experience for both mobile and desktop platforms, accommodating users with or without existing wallets. It simplifies the process of setting up self-custodial wallets for users logging in via email, SMS, or social media accounts. Additionally, it provides flexibility for web3-savvy users to continue using their existing wallets with your application, offering them a choice based on their preference.
Set up
To use Privy with ZeroDev, you have two options: Privy's native integration that utilizes ZeroDev, or a custom integration using Privy's Externally Owned Account (EOA) as a signer. Choose the approach that best fits your needs.
Native Integration
Privy natively supports account abstraction using ZeroDev. This integration allows you to sponsor gas fees, bundle transactions, recover and transfer accounts, utilize session keys.
- For more information and how to get started, visit the Privy's Account Abstraction with ZeroDev documentation.
Custom Integration
If you would like to use ZeroDev directly with a Privy project, you can set up a custom integration using Privys's EOA as a signer.
- Begin by setting up your application with Privy, as detailed in the Privy documentation.
- Privy also offers a quick start guide, available here.
Implementing Custom Integration
Integrating ZeroDev with Privy is straightforward once your application is set up. Privy provides an EOA wallet to use as a signer with Kernel.
Get the Privy wallet's Provider
To begin, ensure your application is integrated with Privy. Detailed guidance is available in the Privy documentation. You should also configure your PrivyProvider to create embedded wallets for your users when they login.
The following example demonstrates the use of Privy's react auth SDK to get the embedded wallet and use it as a signer for ZeroDev.
import { useWallets } from "@privy-io/react-auth";
// Use the `useWallets` hook to get the primary wallet
const { wallets } = useWallets();
// Get the privy embeded wallet.
const embeddedWallet = wallets.find(
(wallet) => wallet.walletClientType === "privy"
);
if (!embeddedWallet) throw new Error("User does not have an embedded wallet");
// Get the provider for the embeded wallet, we will use in the next section
const privyProvider = await embeddedWallet.getEthereumProvider();
Use with ZeroDev
Use the provider from Privy to create a smart account signer, which can be passed to a validator. For detailed guidance on using a validator, refer to our documentation on creating accounts.
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"
import { KERNEL_V3_1, getEntryPoint } from "@zerodev/sdk/constants"
import { createPublicClient } from "viem";
import { polygonAmoy } from 'viem/chains';
const publicClient = createPublicClient({
// Use your own RPC provider (e.g. Infura/Alchemy).
transport: http('https://rpc-amoy.polygon.technology'),
chain: polygonAmoy,
})
// Pass your `smartAccountSigner` to the validator
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
signer: privyProvider,
entryPoint: getEntryPoint("0.7"),
kernelVersion: KERNEL_V3_1
})
// You can now use this ECDSA Validator to create a Kernel account
Templates
A user has helpfully created a ZeroDev + Privy template for React Native (Expo). Check it out here.