> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# `BundlerClient.create`

A Bundler Client is an interface to interact with **ERC-4337 Bundlers** and provides the ability to send and retrieve **User Operations** through **Bundler Actions**.

## Import

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
```

## Usage

```ts twoslash
import { Client, http } from 'viem'
import { BundlerClient } from 'viem/erc4337' // [!code focus]
import { mainnet } from 'viem/chains' // [!code focus]

const client = Client.create({
  chain: mainnet,
  transport: http()
})

const bundlerClient = BundlerClient.create({ // [!code focus]
  client, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc') // [!code focus]
}) // [!code focus]
```

:::info
The Bundler URL above is a public endpoint. Please do not use it in production as you will likely be rate-limited. Consider using [Pimlico's Bundler](https://www.pimlico.io), [Biconomy's Bundler](https://www.biconomy.io), or another Bundler service.
:::

## Parameters

### account

* **Type:** `SmartAccount`

The [Smart Account](/account-abstraction/accounts/smart) to use for the Bundler Client. This will be used for Actions that require an `account` as an argument.

```ts twoslash
import { Account, Client, http } from 'viem'
import {
  BundlerClient,
  CoinbaseSmartAccount,
} from 'viem/erc4337'
import { mainnet } from 'viem/chains'

const client = Client.create({
  chain: mainnet,
  transport: http()
})

const owner = Account.fromPrivateKey('0x...')

const account = await CoinbaseSmartAccount.from({ // [!code focus]
  client, // [!code focus]
  owners: [owner], // [!code focus]
  version: '1.1', // [!code focus]
}) // [!code focus]

const bundlerClient = BundlerClient.create({
  account, // [!code focus]
  client,
  transport: http('https://public.pimlico.io/v2/1/rpc'),
})
```

### chain

* **Type:** [Chain](/docs/chains)

The [Chain](/docs/chains) of the Bundler Client.

```ts twoslash
import { http } from 'viem'
import { BundlerClient } from 'viem/erc4337'
import { mainnet } from 'viem/chains'

const bundlerClient = BundlerClient.create({
  chain: mainnet, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### client

* **Type:** `Client`

The [Client](/docs/clients/create) (pointing to execution RPC) of the Bundler Client.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ // [!code focus]
  chain: mainnet, // [!code focus]
  transport: http() // [!code focus]
}) // [!code focus]

const bundlerClient = BundlerClient.create({
  client, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### dataSuffix

* **Type:** `Hex`

Data to append to the end of User Operation calldata. Useful for adding [transaction attribution](https://oxlib.sh/ercs/erc8021/Attribution).

The bundler client will also inherit `dataSuffix` from the underlying client (e.g., wallet client) if not explicitly set.

Applies to `userOperation.prepare` and `userOperation.send` actions.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
const bundlerClient = BundlerClient.create({
  dataSuffix: '0xdeadbeef', // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### key

* **Type:** `string`
* **Default:** `"bundler"`

A key for the Bundler Client.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
const bundlerClient = BundlerClient.create({
  key: 'foo', // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### name

* **Type:** `string`
* **Default:** `"Bundler Client"`

A name for the Bundler Client.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
const bundlerClient = BundlerClient.create({
  name: 'Foo Bundler Client', // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### paymaster

* **Type:** `true | PaymasterClient | { getData?: Function, getStubData?: Function }`

Sets Paymaster configuration for the Bundler Client to be utilized on User Operations.

* If `paymaster: PaymasterClient`, it will use the provided [Paymaster Client](/account-abstraction/clients/paymaster) for User Operation sponsorship.
* If `paymaster: true`, it will be assumed that the Bundler Client also supports Paymaster RPC methods (e.g. `pm_getPaymasterData`), and use them for User Operation sponsorship.
* If [custom functions](#paymastergetdata-optional) are provided to `paymaster`, it will use them for User Operation sponsorship.

#### Using a Paymaster Client

```ts twoslash
import { PaymasterClient, BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { sepolia } from 'viem/chains'
const paymasterClient = PaymasterClient.create({ // [!code focus]
  transport: http('https://public.pimlico.io/v2/11155111/rpc') // [!code focus]
}) // [!code focus]

const bundlerClient = BundlerClient.create({
  chain: sepolia,
  paymaster: paymasterClient, // [!code focus]
  transport: http('https://public.pimlico.io/v2/11155111/rpc'),
})
```

#### Using the Bundler Client as Paymaster

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const bundlerClient = BundlerClient.create({
  chain: mainnet,
  paymaster: true, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc'),
})
```

#### Using Custom Paymaster Functions

See the [properties below](#paymastergetdata-optional) for more information on how to use custom Paymaster functions.

### paymaster.getData

* **Type:** `PaymasterClient['paymaster']['getData']`

Retrieves paymaster-related User Operation properties to be used for sending the User Operation.

[Read more](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7677.md#pm_getpaymasterdata)

```ts twoslash
import {
  BundlerClient,
  PaymasterClient,
} from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'

const paymasterClient = PaymasterClient.create({
  transport: http('https://api.pimlico.io/v2/1/rpc?apikey={API_KEY}')
})

const bundlerClient = BundlerClient.create({
  chain: mainnet,
  paymaster: { // [!code focus]
    async getData(options) { // [!code focus]
      return paymasterClient.paymaster.getData(options) // [!code focus]
    }, // [!code focus]
  }, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc'),
})
```

### paymaster.getStubData

* **Type:** `PaymasterClient['paymaster']['getStubData']`

Retrieves paymaster-related User Operation properties to be used for gas estimation.

[Read more](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7677.md#pm_getpaymasterstubdata)

```ts twoslash
import {
  BundlerClient,
  PaymasterClient,
} from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'

const paymasterClient = PaymasterClient.create({
  transport: http('https://api.pimlico.io/v2/1/rpc?apikey={API_KEY}')
})

const bundlerClient = BundlerClient.create({
  chain: mainnet,
  paymaster: {
    async getStubData(options) { // [!code focus]
      return paymasterClient.paymaster.getStubData(options) // [!code focus]
    }, // [!code focus]
    async getData(options) {
      return paymasterClient.paymaster.getData(options)
    }
  },
  transport: http('https://public.pimlico.io/v2/1/rpc'),
})
```

### paymasterContext

* **Type:** `unknown`

Paymaster specific fields.

```ts twoslash
import { PaymasterClient, BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const paymasterClient = PaymasterClient.create({
  transport: http('https://public.pimlico.io/v2/1/rpc')
})

const bundlerClient = BundlerClient.create({
  chain: mainnet,
  paymaster: paymasterClient,
  paymasterContext: { // [!code focus]
    policyId: 'abc123' // [!code focus]
  }, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc'),
})
```

### pollingInterval

* **Type:** `number`
* **Default:** `4_000`

Frequency (in ms) for polling enabled Actions.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
const bundlerClient = BundlerClient.create({
  pollingInterval: 10_000, // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})
```

### schema

* **Type:** `RpcSchema`
* **Default:** `BundlerRpcSchema`

Typed JSON-RPC schema for the client.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { z } from 'viem/zod'

const bundlerClient = BundlerClient.create({
  schema: z.RpcSchema.from({ // [!code focus]
    eth_wagmi: { params: z.tuple([z.string()]), returns: z.string() }, // [!code focus]
  }), // [!code focus]
  transport: http('https://public.pimlico.io/v2/1/rpc')
})

const result = await bundlerClient.request({ // [!code focus]
  method: 'eth_wagmi', // [!code focus]
  params: ['hello'], // [!code focus]
}) // [!code focus]
```

### transport

* **Type:** `Transport`

The Transport of the Bundler Client.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const bundlerClient = BundlerClient.create({
  chain: mainnet,
  transport: http('https://public.pimlico.io/v2/1/rpc'), // [!code focus]
})
```

### userOperation

Configuration for User Operations.

#### userOperation.estimateFeesPerGas

* **Type:** `({ account: Account, bundlerClient: BundlerClient, userOperation: UserOperationRequest }) => Promise<{ maxFeePerGas: bigint, maxPriorityFeePerGas: bigint }>`

Prepares fee properties for the User Operation request.

```ts twoslash
import { BundlerClient } from 'viem/erc4337'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const bundlerClient = BundlerClient.create({
  chain: mainnet,
  transport: http('https://public.pimlico.io/v2/1/rpc'),
  userOperation: { // [!code focus]
    async estimateFeesPerGas({ account, bundlerClient, userOperation }) { // [!code focus]
      // Estimate fees per gas for the User Operation. // [!code focus]
      return { // [!code focus]
        maxFeePerGas: 3_000_000_000n, // [!code focus]
        maxPriorityFeePerGas: 2_000_000_000n, // [!code focus]
      } // [!code focus]
    }, // [!code focus]
  }, // [!code focus]
})
```
