Send First Userop¶
This guide will help understanding how to broadcast a 7702 userop using smart wallet implemented here
1. Create Smart Account Client¶
Refer here to understand how to create different smart account clients. Only use wallets which support entrypoint v0.9
import { commonClient } from './client'
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
import { privateKeyToAccount } from 'viem/accounts'
const owner = privateKeyToAccount('0x...') // add private key here
export const smartAccount = await toSimple7702SmartAccount({
implementation: "0xa46cc63eBF4Bd77888AA327837d20b23A63a56B5", // simple7702Account for ep9
client: commonClient,
owner,
});
import { createFreeBundler } from '@etherspot/free-bundler'
import { publicActions, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
const chain = mainnet
export const commonClient = createFreeBundler({chain})
.extend(publicActions)
.extend(walletActions)
2. Send Userop¶
import { commonClient } from './client'
import { toSimple7702SmartAccount } from 'viem/account-abstraction'
import { privateKeyToAccount } from 'viem/accounts'
import { SignAuthorizationReturnType } from 'viem'
const owner = privateKeyToAccount('0x...') // add private key here
const smartAccount = await toSimple7702SmartAccount({
implementation: "0xa46cc63eBF4Bd77888AA327837d20b23A63a56B5", // simple7702Account for ep9
client: commonClient,
owner,
})
// overriding for ep9 address
smartAccount.entryPoint.address = "0x433709009B8330FDa32311DF1C2AFA402eD8D009"
console.log("wallet:: ", smartAccount.address)
// check sender's code to decide if eip7702Auth tuple is necessary for userOp.
const senderCode = await commonClient.getCode({
address: smartAccount.address
})
let authorization: SignAuthorizationReturnType | undefined
const { address: delegateAddress } = smartAccount.authorization
if(senderCode !== `0xef0100${delegateAddress.toLowerCase().substring(2)}`) {
authorization = await commonClient.signAuthorization(smartAccount.authorization)
}
const userOpHash = await commonClient.sendUserOperation({
account: smartAccount,
authorization,
calls: [
{
to: "0x09FD4F6088f2025427AB1e89257A44747081Ed59",
value: parseUnits('0.0000001', 18)
}
]
})
console.log('userOpHash:: ', userOpHash)
import { createFreeBundler } from '@etherspot/free-bundler'
import { publicActions, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
const chain = mainnet
export const commonClient = createFreeBundler({chain})
.extend(publicActions)
.extend(walletActions)
After opening StackBlitz, run:
npx tsx examples/index.ts --private-key 0x...