Account Abstraction
While Account Abstraction is not built into the core viem
library, you can use a third-party library like permissionless.js to integrate with ERC-4337.
Libraries:
permissionless.js
permissionless.js is a TypeScript library built on viem for interacting with ERC-4337 bundlers, paymasters, and User Operations.
Below are instructions for setting up a Bundler Client.
1. Install
bash
npm i permissionless
npm i permissionless
bash
pnpm i permissionless
pnpm i permissionless
bash
bun i permissionless
bun i permissionless
2. Set up a Bundler Client
ts
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { bundlerActions } from 'permissionless'
const bundlerClient = createClient({
chain: mainnet,
transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
}).extend(bundlerActions)
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { bundlerActions } from 'permissionless'
const bundlerClient = createClient({
chain: mainnet,
transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
}).extend(bundlerActions)
3. Consume Actions
Now you can consume Actions that are supported by permissionless.js.
See a full list of Bundler Actions.
ts
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { bundlerActions } from 'permissionless'
const bundlerClient = createClient({
chain: mainnet,
transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
}).extend(bundlerActions)
const supportedEntryPoints = await bundlerClient.supportedEntryPoints()
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { bundlerActions } from 'permissionless'
const bundlerClient = createClient({
chain: mainnet,
transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
}).extend(bundlerActions)
const supportedEntryPoints = await bundlerClient.supportedEntryPoints()