Use Web3Auth with ZeroDev
Web3Auth is a popular embedded wallet provider that supports social logins. While social logins are great, your users still need to onramp in order to pay for gas, which introduces significant friction.
By combining ZeroDev with Web3Auth, you can use Web3Auth to enable a smooth social login experience, while using ZeroDev as the smart wallet to sponsor gas for users, batch transactions, and more.
Set up
To use Web3Auth with ZeroDev, first create an application that integrates with Web3Auth.
- Refer to the Web3Auth documentation site for instructions on setting up an application with the Web3Auth.
- For a quick start, Web3Auth provides example starter projects, available here.
Integration
Integrating ZeroDev with Web3Auth is straightforward after setting up the project. Web3Auth provides an Externally Owned Account (EOA) wallet to use as a signer with Kernel.
Create the Web3Auth object
After following the Web3Auth documentation, you will have access to a web3auth
object as shown below:
import { Web3Auth } from "@web3auth/modal";
// Config options here will be specific to your project. See the Web3Auth docs for more info.
const web3auth = new Web3Auth({
clientId,
chainConfig: {},
uiConfig: {},
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
});
Use with ZeroDev
Use the provider from Web3Auth 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 Web3 from "web3";
import { type Hex, createPublicClient } from "viem"
import { polygonAmoy } from 'viem/chains';
// Get the Provider and EOA address (this will be the address of the signer) from Web3Auth
const web3authProvider = await web3auth.provider;
const web3 = new Web3(provider as any);
const [address] = await web3.eth.getAccounts();
const publicClient = createPublicClient({
// Use your own RPC provider (e.g. Infura/Alchemy).
transport: http('https://rpc-amoy.polygon.technology'),
chain: polygonAmoy,
})
// Pass your `web3authProvider` to the validator
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
signer: web3authProvider,
entryPoint: getEntryPoint("0.7"),
kernelVersion: KERNEL_V3_1
})
// You can now use this ECDSA Validator to create a Kernel account