AlchemySigner
The Alchemy Signer is a SmartAccountSigner
that is powered by Alchemy's Signer Infrastructure. Using the Alchemy Signer, you can get started building embedded accounts with just an Alchemy API key!
Usage
Once you have enabled the Alchemy Signer in the dashboard, getting started is really simple. Install the @alchemy/aa-alchemy
package and initialize your signer:
import { AlchemySigner } from "@alchemy/aa-alchemy";
export const signer = new AlchemySigner({
client: {
// This is created in your dashboard under `https://dashboard.alchemy.com/settings/access-keys`
// NOTE: it is not recommended to expose your API key on the client, instead proxy requests to your backend and set the `rpcUrl`
// here to point to your backend.
connection: { apiKey: "alcht_<KEY>" },
iframeConfig: {
// you will need to render a container with this id in your DOM
iframeContainerId: "turnkey-iframe-container",
},
},
});
Using the Signer with Smart Contract Accounts
Once your signer is authenticated with a user, you can use it to sign User Operations by creating a SmartContractAccount
and passing the signer to it. For example:
import { signer } from "./signer";
export const account = await createMultiOwnerModularAccount({
transport: rpcTransport,
chain,
signer,
});
import { AlchemySigner } from "@alchemy/aa-alchemy";
export const signer = new AlchemySigner({
client: {
// This is created in your dashboard under `https://dashboard.alchemy.com/settings/access-keys`
// NOTE: it is not recommended to expose your API key on the client, instead proxy requests to your backend and set the `rpcUrl`
// here to point to your backend.
connection: { apiKey: "alcht_<KEY>" },
iframeConfig: {
// you will need to render a container with this id in your DOM
iframeContainerId: "turnkey-iframe-container",
},
},
});
Using the Signer as an EOA
WARNING
Note that EOA wallets will not have access to smart account features like gas sponsorship, batched transactions, multi-owner, or plugins. If you want to switch from EOA to smart accounts later, then each user will need to transfer their assets from the EOA account to a new smart account. It is not currently possible to "upgrade" an EOA to a smart contract account, although the community is discussing potential EIPs to do that in the future.
Because the Alchemy Signer has its own address
and supports signing messages as raw hashes, it is possible to use this signer as an EOA directly. To do so, you can adapt the Alchemy Signer to your library of choice and leverage its signMessage
, signTypedData
, and signTransaction
methods directly. The public address of the signer can be accessed via getAddress
.
If you are using viem, then you can use the toViemAccount
method which will allow you to use the signer with a WalletClient
.
import { signer } from "./signer";
import { createWalletClient, http } from "viem";
import { sepolia } from "@alchemy/aa-core";
export const walletClient = createWalletClient({
transport: http("alchemy_rpc_url"),
chain: sepolia,
account: signer.toViemAccount(),
});
import { AlchemySigner } from "@alchemy/aa-alchemy";
export const signer = new AlchemySigner({
client: {
// This is created in your dashboard under `https://dashboard.alchemy.com/settings/access-keys`
// NOTE: it is not recommended to expose your API key on the client, instead proxy requests to your backend and set the `rpcUrl`
// here to point to your backend.
connection: { apiKey: "alcht_<KEY>" },
iframeConfig: {
// you will need to render a container with this id in your DOM
iframeContainerId: "turnkey-iframe-container",
},
},
});
Returns
AlchemySigner
-- an instance of the AlchemySigner that can be used as a signer on SmartContractAccount
instances
Parameters
AlchemySignerParams
-- an object that contains the following properties:
client: AlchemySignerClient | AlchemySignerClientParams
-- the underlying client to use for the signer. TheAlchemySignerClientParams
are defined as follows:connection: ConnectionConfig
-- the api config to use for calling Alchemy's APIs.iframeConfig: IframeConfig
-- the config to use for the iframe that will be used to interact with the signer.iframeElementId?: string
-- the id of the iframe element that will be injected into the DOM [default: "turnkey-iframe"]iframeContainerId: string
-- the id of the iframe container that you have injected into your DOM
sessionConfig?: SessionConfig
-- optional parameter used to configure user sessionssessionKey?: string
-- the key that the session will be stored to in your chosen storage [default: "alchemy-signer-session"]storage?: "localStorage" | "sessionStorage"
-- the storage to use for the session [default: "localStorage"]expirationTimeMs?: number
-- the time in milliseconds that the session will be valid for [default: 15 minutes]