Skip to content
Alchemy Logo

Third Party Bundlers

You can use any ERC-4337 bundler with the v5 stack by combining viem's bundler client with a smart account from @alchemy/smart-accounts. The bundler RPC URL is just a viem transport — point it wherever you like.

import { createBundlerClient } from "viem/account-abstraction";
import { createClient, http } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { sepolia } from "viem/chains";
import { toLightAccount } from "@alchemy/smart-accounts";
 
// 1. RPC client for chain reads — uses any RPC provider.
const rpcClient = createClient({
  chain: sepolia,
  transport: http("https://your-rpc-provider.example.com"),
});
 
// 2. Smart account implementation from @alchemy/smart-accounts.
const owner = privateKeyToAccount(generatePrivateKey());
const account = await toLightAccount({
  client: rpcClient,
  owner,
  version: "v2.0.0",
});
 
// 3. Bundler client pointed at any third-party bundler URL.
const bundlerClient = createBundlerClient({
  account,
  client: rpcClient,
  chain: sepolia,
  transport: http("https://your-third-party-bundler.example.com"),
});
 
// 4. Send a user operation through the third-party bundler.
const hash = await bundlerClient.sendUserOperation({
  calls: [{ to: "0x0000000000000000000000000000000000000000", value: 0n, data: "0x" }],
});

The rpcClient (chain reads) and bundlerClient (user-operation RPCs) use independent transports, so you can already point them at different providers. Use one provider's URL for rpcClient and another for bundlerClient and you're done — no special split transport needed.

If you'd rather route a single client across multiple providers (e.g. fall back to a different RPC on certain methods), use viem's fallback transport.

Was this page helpful?