Using Viem SDK
This guide explains how to use the Biconomy Bundler with the Viem SDK to perform smart account transactions. You can use any of the smart accounts supported by viem.
Create bundler client
- Follow the step-by-step guide for executing a transaction with the viem SDK.
- To create a bundler instance, pass the Biconomy Bundler URL to the createBundlerClient method.
In the example below, we will send 0.001 ETH to a random address.
import { createPublicClient, http, parseEther } from 'viem';
import { createBundlerClient, toCoinbaseSmartAccount, createPaymasterClient, toSoladySmartAccount } from 'viem/account-abstraction';
import { sepolia } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
const main = async () => {
const client = createPublicClient({
chain: sepolia,
transport: http(),
})
const owner = privateKeyToAccount('PRIVATE_KEY')
console.log(owner.address)
const account = await toCoinbaseSmartAccount({
client,
owners: [owner]
})
const bundlerClient = createBundlerClient({
account,
client,
transport: http('https://bundler.biconomy.io/api/v2/11155111/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44'),
})
console.log(account.address);
const userOpHash = await bundlerClient.sendUserOperation({
account,
calls: [{
to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
value: parseEther('0.001')
}]
})
console.log(userOpHash)
}
main()