# 4337 Bundler

The Openfort 4337 Bundler is a high-performance, ERC-4337 compliant bundler that aggregates UserOperations and submits them to the blockchain. As a fully compliant ERC-4337 bundler, it is designed for reliability and speed, ensuring your users' transactions are included quickly even during network congestion.

## Overview

A 4337 bundler is a specialized transaction relayer that implements the ERC-4337 Account Abstraction standard. The Openfort ERC-4337 bundler:

1. Receives UserOperations from applications
2. Validates and simulates operations
3. Bundles multiple operations into transactions
4. Submits them to the blockchain via the EntryPoint contract

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

:::warning[Dashboard Visibility]
Transactions from smart accounts that are not natively supported by Openfort will not appear in the [Openfort Dashboard](https://dashboard.openfort.io). For full dashboard visibility and transaction tracking, use one of the [supported smart account implementations](/docs/configuration/addresses).
:::

## Getting Started

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

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

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

```http
Authorization: Bearer YOUR_OPENFORT_PUBLISHABLE_KEY
```

Get your public key from the [Openfort Dashboard](https://dashboard.openfort.io).

## Available Endpoints

| Method | Description |
|--------|-------------|
| [`eth_sendUserOperation`](/docs/products/infrastructure/bundler/endpoints#eth_senduseroperation) | Submit a UserOperation for inclusion |
| [`eth_estimateUserOperationGas`](/docs/products/infrastructure/bundler/endpoints#eth_estimateuseroperationgas) | Estimate gas for a UserOperation |
| [`eth_getUserOperationReceipt`](/docs/products/infrastructure/bundler/endpoints#eth_getuseroperationreceipt) | Get the receipt for a submitted operation |
| [`eth_getUserOperationByHash`](/docs/products/infrastructure/bundler/endpoints#eth_getuseroperationbyhash) | Retrieve a UserOperation by its hash |
| [`eth_supportedEntryPoints`](/docs/products/infrastructure/bundler/endpoints#eth_supportedentrypoints) | List supported EntryPoint contracts |

## Quick Example

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

```typescript
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 4337 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 sponsored UserOperation
// The policyId specifies a transaction-scoped gas sponsorship policy.
// Omit paymasterContext to use project-scoped policies instead.
// See: /docs/products/infrastructure/paymaster/ethereum
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

* [Endpoint Reference](/docs/products/infrastructure/bundler/endpoints) - Detailed documentation for all 4337 bundler methods
* [Error Reference](/docs/products/infrastructure/bundler/errors) - Common errors and how to resolve them
* [Supported Chains](/docs/configuration/chains) - List of networks where the ERC-4337 bundler is available
