getBundlerClient
getBundlerClient
is a method on EthersProviderAdapter
that gets the underlying viem client which has EIP-4337 capability.
Usage
ts
import { provider } from "./ethers-provider";
// get the provider's underlying viem client with EIP-4337 capabilities
const client = provider.getBundlerClient();
ts
import {
createSimpleSmartAccount,
getChain,
getDefaultSimpleAccountFactoryAddress,
} from "@alchemy/aa-core";
import { EthersProviderAdapter } from "@alchemy/aa-ethers";
import { Alchemy, Network } from "alchemy-sdk";
import { signer } from "snippets/aa-core/lightAccountClient";
import { http } from "viem";
// 1. Create alchemy instance
const alchemy = new Alchemy({
apiKey: process.env.API_KEY!,
network: Network.MATIC_MUMBAI,
});
const ethersProvider = await alchemy.config.getProvider();
const chain = getChain(ethersProvider.network.chainId);
// 2. smart account client from alchemy's ethers provider and connect with simple smart account
export const provider = EthersProviderAdapter.fromEthersProvider(
ethersProvider
).connectToAccount(
await createSimpleSmartAccount({
chain,
signer,
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
transport: http(
`${chain.rpcUrls.alchemy.http[0]}/${ethersProvider.apiKey}`
),
})
);
Returns
BundlerClient
The provider's underlying BundlerClient