AccountSigner
AccountSigner
is an extension of the ethers.js Signer
which includes a implementation of SmartContractAccount
to integrate EIP-4337 smart accounts. The interface is similar to a standard Signer
, with additional methods to leverage the Alchemy Account Abstraction stack.
Notable differences between EthersProviderAdapter
and JsonRpcProvider
are implementations for:
getAddress
-- gets theAccountSigner
's smart account address.signMessage
-- signs messages with theAccountSigner
's EOA signer address.sendTransaction
-- sends transactions on behalf of theAccountSigner
's connected signer, with request and response formatted as if you were using the ethers.js library.getBundlerClient
-- gets the underlying viem client with ERC-4337 compatibility.connect
-- connects the inputted provider to an account and returns anAccountSigner
.
Usage
ts
import { accountSigner } from "./ethers-signer";
// get the account signer's account address
const address = await accountSigner.getAddress();
// sign message with the account signer's EOA signer address
const signedMessage = await accountSigner.signMessage("test");
// sends transaction on behalf of the smart account connected EOA signer
const txn = await accountSigner.sendTransaction({
to: "0xRECIPIENT_ADDRESS",
data: "0xDATA",
});
// get the account signer's underlying viem client with EIP-4337 capabilities
const client = accountSigner.getBundlerClient();
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,
})
);