Skip to main content

Bundler

The Bundler class provides access to ERC-4337 Bundler JSON-RPC API methods for estimating user operation gas and sending user operations.

The Bundler class creates a Bundler instance with a Bundler RPC URL or an EIP-1193-shaped Transport.

Usage​

Import​

import { Bundler } from "abstractionkit";

How to Use​

Initialize a Bundler with your desired bundler RPC URL:

const bundlerRPC = "https://api.candide.dev/public/v3/11155111";

const bundler: Bundler = new Bundler(bundlerRPC);

You can also pass a custom transport when you need request cancellation, custom headers, retries, telemetry, or an injected provider:

import { Bundler, HttpTransport } from "abstractionkit";

const bundler = new Bundler(
new HttpTransport("https://api.candide.dev/public/v3/11155111"),
);

Then consume Bundler methods:

const entrypointAddresses = await bundler.supportedEntryPoints();

You can also fork the complete code and follow along.

Parameters​

bundlerRPC string | Transport​

Bundler, CandidePaymaster, and Erc7677Paymaster accept either an RPC URL string or a Transport. Each service also exposes transport, which replaces the old rpcUrl field.

Methods​

chainId​

Returns the chain ID of the network the bundler is operating on.

Usage​

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

const bundlerRPC = "https://api.candide.dev/public/v3/11155111";
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/public/v3/11155111";
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/public/v3/11155111";
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/public/v3/11155111";
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, or null if the bundler does not know it. Numeric UserOperation fields (nonce, gas limits, and fees) are returned as bigint. blockNumber, blockHash and transactionHash are null while the UserOperation is pending, and blockNumber is a bigint once it is included.

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

const bundlerRPC = "https://api.candide.dev/public/v3/11155111";
const bundler: Bundler = new Bundler(bundlerRPC);
const userOperationHash = "0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb";

const userOperation = await bundler.getUserOperationByHash(userOperationHash);
Example Response
{
userOperation: {
sender: '0xbA1Cd2470F46778c9748ce676c00Ba48D6f0b89d',
nonce: 2n,
initCode: '0x',
callData: '0xf34308ef0000000000000000000000001a02592a3484c2077d2e5d24482497f85e1980c6000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
callGasLimit: 42472n,
verificationGasLimit: 98907n,
preVerificationGas: 52060n,
maxFeePerGas: 1000000030n,
maxPriorityFeePerGas: 1000000000n,
paymasterAndData: '0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020000000000000000000000000000000000000000003000064cfa9640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064c82c6734b770b84cdf835ba3d1df6237178138c98ec5bef635cf8f3f2ac1fa3c0528a98b33c5ec5d5ab559f79ed3cac4ebb6b57de127840b433557938e46151b',
signature: '0x8a45a5eadb9f2f4b552ec20fa63424dbecca28a7a6f43f065298574861869071446b622ccc17c2eab539115afceb314f859a1cc7e9289935c4fddce833cda3ca1c'
},
entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
blockNumber: 9472404n,
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/public/v3/11155111";
const bundler: Bundler = new Bundler(bundlerRPC);
const userOperationHash = "0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb";

const userOperationReceipt = await bundler.getUserOperationReceipt(
userOperationHash
);
Example Response
{
userOpHash: '0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb',
entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
sender: '0xba1cd2470f46778c9748ce676c00ba48d6f0b89d',
nonce: 2n,
paymaster: '0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020',
actualGasCost: 130079001821106n,
actualGasUsed: 130079n,
success: true,
logs: [
{
address: '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789',
topics: [
'0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f',
'0xb348b32bc9b9e90620839c3926db401558806b03b2a46dc6de21d3a4ed8412fb',
'0x000000000000000000000000ba1cd2470f46778c9748ce676c00ba48d6f0b89d',
'0x0000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e020'
],
data: '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000764e60b23fb2000000000000000000000000000000000000000000000000000000000001fc1f',
blockNumber: '0x908994',
transactionHash: '0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4',
// ...
}
],
receipt: {
blockHash: '0xd7d5471af5fdf2359031a5b0b7ac4c664b62aaaa0e4a65c248ef0fe78b7eeb9f',
blockNumber: 9472404n,
from: '0x3cfdc212769c890907bce93d3d8c2c53de6a7a89',
cumulativeGasUsed: 6256651n,
gasUsed: 127081n,
logs: [ /* every log in the bundle transaction, same shape as above */ ],
logsBloom: '0x00000000000000000000000000000108...',
transactionHash: '0xc8262db778457c24d8faa043879de973d6c8699ddb518b3864004d99093ce6e4',
transactionIndex: 47n,
effectiveGasPrice: 105n
}
}

JSON-RPC Method​

eth_getUserOperationReceipt