Skip to content

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:

  1. getAddress -- gets the AccountSigner's smart account address.
  2. signMessage -- signs messages with the AccountSigner's EOA signer address.
  3. sendTransaction -- sends transactions on behalf of the AccountSigner's connected signer, with request and response formatted as if you were using the ethers.js library.
  4. getBundlerClient -- gets the underlying viem client with ERC-4337 compatibility.
  5. connect -- connects the inputted provider to an account and returns an AccountSigner.

Usage

example.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();