Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Bundler

The Openfort Bundler is a high-performance ERC-4337 bundler that aggregates UserOperations and submits them to the blockchain. It's designed for reliability and speed, ensuring your users' transactions are included quickly.

Overview

ERC-4337 bundlers are specialized relayers that:

  1. Receive UserOperations from applications
  2. Validate and simulate operations
  3. Bundle multiple operations into transactions
  4. Submit them to the blockchain via the EntryPoint contract

The bundler handles all this complexity, providing a JSON-RPC interface for your application.

Getting Started

To use the bundler, make JSON-RPC requests to:

https://api.openfort.io/rpc/{chainId}

Replace {chainId} with the appropriate chain ID. Include your Openfort publishable key in the Authorization header:

Authorization: Bearer YOUR_OPENFORT_PUBLISHABLE_KEY

Get your public key from the Openfort Dashboard.

Available Endpoints

MethodDescription
eth_sendUserOperationSubmit a UserOperation for inclusion
eth_estimateUserOperationGasEstimate gas for a UserOperation
eth_getUserOperationReceiptGet the receipt for a submitted operation
eth_getUserOperationByHashRetrieve a UserOperation by its hash
eth_supportedEntryPointsList supported EntryPoint contracts

Quick Example

This example shows how to use the Openfort bundler with viem to send a sponsored UserOperation:

import { createPublicClient, http } from 'viem'
import { sepolia } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import {
  createBundlerClient,
  createPaymasterClient,
  toCoinbaseSmartAccount
} from 'viem/account-abstraction'
 
// Create a public client for reading blockchain state
const client = createPublicClient({
  chain: sepolia,
  transport: http(),
})
 
// Create the paymaster client with Openfort
const paymasterClient = createPaymasterClient({
  transport: http('https://api.openfort.io/rpc/11155111', {
    fetchOptions: {
      headers: {
        'Authorization': 'Bearer YOUR_OPENFORT_PUBLISHABLE_KEY',
      },
    },
  }),
})
 
// Create a smart account (using Coinbase Smart Account as an example)
const owner = privateKeyToAccount(process.env.PRIVATE_KEY)
const account = await toCoinbaseSmartAccount({
  client,
  owners: [owner],
  version: '1.1',
})
 
// Create the bundler client with the Openfort bundler
const bundlerClient = createBundlerClient({
  account,
  paymaster: paymasterClient,
  client,
  paymasterContext: {
    policyId: 'YOUR_POLICY_ID_HERE'
  },
  transport: http('https://api.openfort.io/rpc/11155111', {
    fetchOptions: {
      headers: {
        'Authorization': 'Bearer YOUR_OPENFORT_PUBLISHABLE_KEY',
      },
    },
  }),
})
 
// Send a UserOperation
const hash = await bundlerClient.sendUserOperation({
  calls: [{
    to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
    value: 0n,
    data: '0x1234',
  }],
})
 
// Wait for the UserOperation receipt
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash })
console.log('UserOperationReceipt:', receipt)

Next Steps

Copyright © 2023-present Alamas Labs, Inc