To use the v5 stack on a chain that Alchemy doesn't support, define the chain with viem's defineChain and point your public client and bundler client at your own RPC and bundler URLs.
import { createBundlerClient } from "viem/account-abstraction";
import { createClient, defineChain, http } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { toLightAccount } from "@alchemy/smart-accounts";
// 1. Define your chain.
const myChain = defineChain({
id: 12345,
name: "MyChain",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: { http: ["https://rpc.mychain.example.com"] },
},
});
// 2. RPC client + smart account against that chain.
const rpcClient = createClient({ chain: myChain, transport: http() });
const owner = privateKeyToAccount(generatePrivateKey());
const account = await toLightAccount({
client: rpcClient,
owner,
version: "v2.0.0",
});
// 3. Bundler client at the third-party bundler RPC.
const bundlerClient = createBundlerClient({
account,
client: rpcClient,
chain: myChain,
transport: http("https://bundler.mychain.example.com"),
});
const hash = await bundlerClient.sendUserOperation({
calls: [{ to: "0x0000000000000000000000000000000000000000", value: 0n, data: "0x" }],
});To add gas sponsorship via a third-party paymaster on this chain, configure viem's bundler client with that provider's ERC-7677 paymaster RPC.