Using a different RPC Provider
The SmartAccountClient
within @alchemy/aa-core
is unopinionated about which bundler you use, so you can connect to any RPC provider really simply.
Usage
If we look at the example for creating a SmartAccountClient
:
import {
createLightAccount,
lightAccountClientActions,
} from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountSigner,
createSmartAccountClient,
polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
export const chain = polygonMumbai;
export const signer: SmartAccountSigner =
LocalAccountSigner.mnemonicToAccountSigner("YOUR_OWNER_MNEMONIC");
export const rpcTransport = http(
"https://polygon-mumbai.g.alchemy.com/v2/demo"
);
export const smartAccountClient = createSmartAccountClient({
transport: rpcTransport,
chain,
account: await createLightAccount({
transport: rpcTransport,
chain,
signer,
}),
}).extend(lightAccountClientActions);
You can see that we set the transport
to http("https://polygon-mumbai.g.alchemy.com/v2/demo")
. You can swap out that the url in the http
function to any other provider's URL.
WARNING
Depending on your provider, you may have to pass in custom logic for the gasEstimator
and feeEstimator
properties when calling createSmartAccountClient
. Consult with your provider on what the correct logic is.
Splitting Bundler traffic and Node RPC traffic
It might be the case that you want to use a different RPC provider for your bundler traffic and your node traffic. This is a common use case, and you can do this by leveraging the split
transport and passing it to your createSmartAccountClient
call. For example:
import { createSmartAccountClient, sepolia, split } from "@alchemy/aa-core";
import { http } from "viem";
const bundlerMethods = [
"eth_sendUserOperation",
"eth_estimateUserOperationGas",
"eth_getUserOperationReceipt",
"eth_getUserOperationByHash",
"eth_supportedEntryPoints",
];
const splitTransport = split({
overrides: [
{
methods: bundlerMethods,
transport: http("BUNDLER_RPC_URL"),
},
],
fallback: http("OTHER_RPC_URL"),
});
export const client = createSmartAccountClient({
chain: sepolia,
transport: splitTransport,
});
Zora and Fraxtal
Using a split Bundler and Node RPC setup is required for Fraxtal, Fraxtal Testnet, Zora, and Zora Sepolia networks since Alchemy currently only supports Account Abstraction endpoints for those networks. Please refer to documentation from Frax and Zora about RPC options.