Skip to main content

Bundler

A Bundler is a class to an ERC-4337 Bundler JSON-RPC API methods such as estimating user operation gas, and sending user operations.

The Bundler class sets up a Bundler Instance with a Bundler RPC URL.

Usage

Import

import { Bundler } from "abstractionkit";

How to use

Initialize a Bundler with your desired bundler RPC url

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";

const bundler: Bundler = new Bundler(bundlerRPC);

Then you can consume Bundler methods:

const entrypointAddresses = await bundler.supportedEntryPoints();

Paramaters

bundlerURL string

Methods

chainId

Returns chain ID of the current network that the bundler is operating in

Usage

example.ts
import { Bundler } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);
const getChainId = await bundler.chainId();
Example Response
0xaa36a7

JSON-RPC Method

eth_chainId

supportedEntryPoints

Returns the list of the entryPoint addresses supported by the bundler

Usage

example.ts
import { Bundler } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);
const entrypointAddresses = await bundler.supportedEntryPoints();
Example Response
[
'0x0000000071727De22E5E9d8BAf0edAc6f37da032',
'0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
]

JSON-RPC Method

eth_supportedEntryPoints

estimateUserOperationGas

Generates and returns an estimate of how much gas is necessary to allow the user operation to complete, given a UserOperations.

Usage

See a full example in getting-started guide

example.ts
import { Bundler, UserOperationV7 } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);

// Use createUserOperation() to help you construct the userOp below
const userOperation = smartAccount.createUserOperation(..)
const entryPointAddress = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";

const estimation = await bundler.estimateUserOperationGas(userOperation, entryPointAddress);
Example Response
{
callGasLimit: 58588n,
preVerificationGas: 45628n,
verificationGasLimit: 94374n
}

JSON-RPC Method

eth_estimateUserOperationGas

sendUserOperation

Asks the bundler to sign and submit a User Operation

Usage

See a full example in getting-started guide

example.ts
import { Bundler } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);
const entrypointAddress = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
// Use createUserOperation() to help you construct the userOp below
const userOperation = smartAccount.createUserOperation(..)

const userOperationHash = await bundler.sendUserOperation(userOperation, entrypointAddress);
Example Response
'0x0ff052095987556f476c6e6b7cdff65cc6191d2cede50a109fe6977c3287fc9a'

JSON-RPC Method

eth_sendUserOperation

getUserOperationByHash

Returns a UserOperation by its hash returned from sendUserOperation

Usage
example.ts
import { Bundler } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);
const userOperationHash = "0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb";

const userOperation = await bundler.getUserOperationByHash(userOperationHash);
Example Response
{
userOperation: {
sender: '0xbA1Cd2470F46778c9748ce676c00Ba48D6f0b89d',
nonce: '0x2',
initCode: '0x',
callData: '0xf34308ef0000000000000000000000001a02592a3484c2077d2e5d24482497f85e1980c6000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: '0xa5e8',
verificationGasLimit: '0x1825b',
preVerificationGas: '0xcb5c',
maxFeePerGas: '0x3b9aca1e',
maxPriorityFeePerGas: '0x3b9aca00',
paymasterAndData: '0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020000000000000000000000000000000000000000003000064cfa9640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064c82c6734b770b84cdf835ba3d1df6237178138c98ec5bef635cf8f3f2ac1fa3c0528a98b33c5ec5d5ab559f79ed3cac4ebb6b57de127840b433557938e46151b',
signature: '0x8a45a5eadb9f2f4b552ec20fa63424dbecca28a7a6f43f065298574861869071446b622ccc17c2eab539115afceb314f859a1cc7e9289935c4fddce833cda3ca1c'
},
entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
blockNumber: '0x908994',
blockHash: '0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f',
transactionHash: '0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4'
}

JSON-RPC Method

eth_getUserOperationByHash

getUserOperationReceipt

Returns the receipt of a UserOperation by its hash returned from sendUserOperation

Usage

example.ts
import { Bundler } from "abstractionkit";

const bundlerRPC = "https://api.candide.dev/bundler/version/network/YOUR_API_KEY";
const bundler: Bundler = new Bundler(bundlerRPC);
const userOperationHash = "0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb";

const userOperationReceipt = await bundler.getUserOperationReceipt(
userOperationHash
);
Example Response
{
userOpHash: '0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb',
entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
sender: '0xba1cd2470f46778c9748ce676c00ba48d6f0b89d',
nonce: '0x2',
paymaster: '0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020',
actualGasCost: 130079001821106,
actualGasUsed: 130079,
success: true,
logs: '[]',
receipt: {
blockHash: '0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f',
blockNumber: '0x908994',
from: '0x3cfdc212769c890907bce93d3d8c2c53de6a7a89',
cumulativeGasUsed: '0x5f780b',
gasUsed: '0x1f069',
logs: '[{"address":"0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789","blockHash":"0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f","blockNumber":"0x908994","data":"0x","logIndex":"0x5b","removed":false,"topics":["0xbb47ee3e183a558b1a2ff0874b079f3fc5478b7454eacf2bfc5af2ff5878f972"],"transactionHash":"0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4","transactionIndex":"0x2f"},{"address":"0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020","blockHash":"0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f","blockNumber":"0x908994","data":"0x0000000000000000000000000000000000000000000000000000000000000000","logIndex":"0x5c","removed":false,"topics":["0xa050a122b4c0e369e3385eb6b7cccd8019638b2764de67bec0af99130ddf8471","0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb","0x000000000000000000000000ba1cd2470f46778c9748ce676c00ba48d6f0b89d","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":"0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4","transactionIndex":"0x2f"},{"address":"0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789","blockHash":"0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f","blockNumber":"0x908994","data":"0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000764e60b23fb2000000000000000000000000000000000000000000000000000000000001fc1f","logIndex":"0x5d","removed":false,"topics":["0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f","0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb","0x000000000000000000000000ba1cd2470f46778c9748ce676c00ba48d6f0b89d","0x0000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e020"],"transactionHash":"0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4","transactionIndex":"0x2f"}]',
logsBloom: '0x000000000000000000000000000001080000000000000000000000000000000000080000000000000002000100000000001000000000000000000a00000000000000000000000000000000040000000000000000010000000000000000800000000000000a0000000000002000000800000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000004000000000040400000000004000000000000000000000002000000000000000000000000000001200000000000000000000000000000100000000022000000000000000000000000000000000000000000000000000000000010000000',
transactionHash: '0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4',
transactionIndex: '0x2f',
effectiveGasPrice: '0x69'
}
}

JSON-RPC Method

eth_getUserOperationReceipt