EthersProviderAdapter
EthersProviderAdapter
is an extension of the ethers.js
JsonRpcProvider
which includes a SmartAccountClient
field to integrate EIP-4337 smart accounts. The interface is similar to a standard JsonRpcProvider
, with additional methods to leverage the Alchemy Account Abstraction stack.
Notable differences between EthersProviderAdapter
and JsonRpcProvider
are implementations for:
send
-- sends EIP-1193-compliant requests through the account provider.connectToAccount
-- connects the provider to an account and returns anAccountSigner
.getBundlerClient
-- gets the underlying viem client with ERC-4337 compatibility.fromEthersProvider
-- static method that converts anethers.js
JsonRpcProvider
to anEthersProviderAdapter
.
Usage
example.ts
import { provider } from "./ethers-provider";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core";
import { polygonMumbai } from "@alchemy/aa-core";
import { http } from "viem";
// EIP-1193 compliant requests
const chainId = await provider.send("eth_chainId", []);
// get the provider's underlying viem client with EIP-4337 capabilities
const client = provider.getBundlerClient();
// connect the provider to an AccountSigner
const signer: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
process.env.YOUR_OWNER_MNEMONIC!
);
const accountSigner = provider.connectToAccount(
await createLightAccount({
chain,
transport: http("RPC_URL"),
signer,
})
);