connect
connect
is a method on AccountSigner
that you can call to connect an EthersProviderAdapter
to this Signer. This lets the returned AccountSigner
leverage the provider when signing messages, sending user operations and transactions for the smart account using the signer.
Usage
ts
import { accountSigner } from "./ethers-signer";
// changing the ethers provider for the account signer
const alchemy = new Alchemy({
apiKey: process.env.API_KEY!,
network: Network.SEPOLIA, // new chain -> new provider
});
const ethersProvider = await alchemy.config.getProvider();
const newProvider = EthersProviderAdapter.fromEthersProvider(ethersProvider);
// connecting the account signer to ethers
const newAccountSigner = accountSigner.connect(newProvider);
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
A new instance of a connected AccountSigner
Parameters
provider: EthersProviderAdapter
the EthersProviderAdapter
to connect with this AccountSigner