connectToAccount
connectToAccount
is a method on EthersProviderAdapter
that you can optionally call to connect the provider to an account and returns a AccountSigner
. This enables the returned AccountSigner
to leverage the provider when signing messages, UserOperations, and transactions for a smart account using the connected EOA signer account.
Usage
ethers-signer.ts
import { createLightAccount } from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountSigner,
polygonMumbai,
} from "@alchemy/aa-core";
import { http } from "viem";
import { provider } from "./ethers-provider.js";
const eoaSigner: SmartAccountSigner =
LocalAccountSigner.mnemonicToAccountSigner(process.env.YOUR_OWNER_MNEMONIC!);
const chain = polygonMumbai;
// 2. Connect the provider to the smart account signer
export const accountSigner = provider.connectToAccount(
await createLightAccount({
chain,
transport: http("RPC_URL"),
signer: eoaSigner,
})
);
Returns
AccountSigner<TAccount extends SmartContractAccount>
A new instance of a connected AccountSigner
for any implementation class of SmartContractAccount
Parameters
account: TAccount extends SmartContractAccount
A function that takes in the provider's rpcClient and returns an AccountSigner