BaseAlchemySigner

Defined in: account-kit/signer/src/base.ts:119

Base abstract class for Alchemy Signer, providing authentication and session management for smart accounts. Implements the SmartAccountAuthenticator interface and handles various signer events.

Extended by

Type Parameters

Type Parameter

TClient extends BaseSignerClient

Implements

  • SmartAccountAuthenticator<AuthParams, User, TClient>

Constructors

Constructor

1new BaseAlchemySigner<TClient>(param0): BaseAlchemySigner<TClient>;

Defined in: account-kit/signer/src/base.ts:138

Initializes an instance with the provided client and session configuration. This function sets up the internal store, initializes the session manager, registers listeners and initializes the session manager to manage session state.

Parameters

ParameterTypeDescription

param0

BaseAlchemySignerParams<TClient>

Object containing the client and session configuration

Returns

BaseAlchemySigner<TClient>

Properties

PropertyTypeDefault valueDescription

addMfa

(params) => Promise<AddMfaResult>

undefined

Initiates the setup of a new MFA factor for the current user. The factor will need to be verified using verifyMfa before it becomes active.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.addMfa({ multiFactorType: "totp" });
15// Result contains multiFactorTotpUrl to display as QR code

Throws

If no user is authenticated

addPasskey

(params?) => Promise<string[]>

undefined

Adds a passkey to the user’s account

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.addPasskey()

authenticate

(params) => Promise<User>

undefined

Authenticate a user with either an email or a passkey and create a session for that user

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.authenticate({
15 type: "email",
16 email: "[email protected]",
17});

disconnect

() => Promise<void>

undefined

Clear a user session and log them out

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14await signer.disconnect();

exportWallet

TClient["exportWallet"]

undefined

Used to export the wallet for a given user If the user is authenticated with an Email, this will return a seed phrase If the user is authenticated with a Passkey, this will return a private key

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// the params passed to this are different based on the specific signer
15const result = signer.exportWallet()

Param

exportWallet parameters

getAddress

() => Promise<`0x${string}`>

undefined

Retrieves the address of the current user by calling the whoami method on this.inner.

getMfaFactors

() => Promise<{ multiFactors: MfaFactor[]; }>

undefined

Retrieves the list of MFA factors configured for the current user.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const { multiFactors } = await signer.getMfaFactors();

Throws

If no user is authenticated

getPasskeyStatus

() => Promise<{ isPasskeyAdded: boolean; }>

undefined

inner

TClient

undefined

removeEmail

() => Promise<void>

undefined

Removes the email for the authenticated user, disallowing them from login with that email.

Throws

If the user is not authenticated

removeMfa

(params) => Promise<{ multiFactors: MfaFactor[]; }>

undefined

Removes existing MFA factors by their IDs.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.removeMfa({
15 multiFactorIds: ["factor-id-1", "factor-id-2"]
16});

Throws

If no user is authenticated

removePasskey

(authenticatorId) => Promise<void>

undefined

Removes a passkey from a user’s account

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const authMethods = await signer.listAuthMethods();
15const passkey = authMethods.passkeys[0];
16
17const result = await signer.removePasskey(passkey.authenticatorId);

removePhoneNumber

() => Promise<void>

undefined

Removes the phone number for the authenticated user, disallowing them from login with that phone number.

Throws

If the user is not authenticated

sendVerificationCode

(type, contact) => Promise<{ otpId: string; }>

undefined

Initiates an OTP (One-Time Password) verification process for a user contact. Use this method before calling setEmail with verification code to verify ownership of the email address.

Throws

If the user is not authenticated

setPhoneNumber

(params) => Promise<void>

undefined

Sets the phone number for the authenticated user, allowing them to login with that phone number. sendVerificationCode should be called first to obtain the code.

Throws

If the user is not authenticated

signAuthorization

(unsignedAuthorization) => Promise<SignedAuthorization<number>>

undefined

Signs an EIP-7702 Authorization and then returns the authorization with the signature.

Example

import { 
class AlchemyWebSigner

A SmartAccountSigner that can be used with any SmartContractAccount

AlchemyWebSigner
} from "@account-kit/signer";
const
const signer: AlchemyWebSigner
signer
= new
new AlchemyWebSigner(params: AlchemySignerParams): AlchemyWebSigner

Initializes an instance with the provided Alchemy signer parameters after parsing them with a schema.

AlchemyWebSigner
({
client: { connection: ({ apiKey: string; rpcUrl?: undefined; jwt?: undefined; } | { jwt: string; rpcUrl?: undefined; apiKey?: undefined; } | { rpcUrl: string; apiKey?: undefined; jwt?: undefined; } | { rpcUrl: string; jwt: string; apiKey?: undefined; }) & { chainAgnosticUrl?: string | undefined; }; iframeConfig: { iframeContainerId: string; iframeElementId?: string | undefined; }; rpId?: string | undefined; rootOrgId?: string | undefined; oauthCallbackUrl?: string | undefined; enablePopupOauth?: boolean | undefined; } | AlchemySignerWebClient
client
: {
connection: ({ apiKey: string; rpcUrl?: undefined; jwt?: undefined; } | { jwt: string; rpcUrl?: undefined; apiKey?: undefined; } | { rpcUrl: string; apiKey?: undefined; jwt?: undefined; } | { rpcUrl: string; jwt: string; apiKey?: undefined; }) & { chainAgnosticUrl?: string | undefined; }
connection
: {
rpcUrl: string
rpcUrl
: "/api/rpc",
},
iframeConfig: { iframeContainerId: string; }
iframeConfig
: {
iframeContainerId: string
iframeContainerId
: "alchemy-signer-iframe-container",
}, }, }); const
const tx: SignedAuthorization<number>
tx
= await
const signer: AlchemyWebSigner
signer
.
BaseAlchemySigner<AlchemySignerWebClient>.signAuthorization: (unsignedAuthorization: AuthorizationRequest<number>) => Promise<SignedAuthorization<number>>

Signs an EIP-7702 Authorization and then returns the authorization with the signature.

signAuthorization
({
contractAddress: `0x${string}`
contractAddress
: "0x1234123412341234123412341234123412341234",
chainId: number

Chain ID.

chainId
: 1,
nonce: number

Nonce of the EOA to delegate to.

nonce
: 0,
});

signerType

"alchemy-signer" | "rn-alchemy-signer"

"alchemy-signer"

signMessage

(msg) => Promise<`0x${string}`>

undefined

Signs a raw message after hashing it.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const signature = await signer.signMessage("Hello, world!");

signTransaction

<serializer, transaction>(transaction, options?) => Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, `0x${string}`> extends true ? TransactionSerialized<GetTransactionType<transaction>> : `0x${string}`>

undefined

Serializes a transaction, signs it with a raw message, and then returns the serialized transaction with the signature.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const tx = await signer.signTransaction({
15 to: "0x1234",
16 value: "0x1234",
17 data: "0x1234",
18});

signTypedData

<TTypedData, TPrimaryType>(params) => Promise<`0x${string}`>

undefined

Signs a typed message by first hashing it and then signing the hashed message using the signRawMessage method.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const signature = await signer.signTypedData({
15 domain: {},
16 types: {},
17 primaryType: "",
18 message: {},
19});

verifyMfa

(params) => Promise<{ multiFactors: MfaFactor[]; }>

undefined

Verifies a newly created MFA factor to complete the setup process.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.verifyMfa({
15 multiFactorId: "factor-id",
16 multiFactorCode: "123456" // 6-digit code from authenticator app
17});

Throws

If no user is authenticated

Methods

addOauthProvider()

1addOauthProvider(args): Promise<OauthProviderInfo>;

Defined in: account-kit/signer/src/base.ts:1260

Handles OAuth authentication by augmenting the provided arguments with a type and performing authentication based on the OAuth mode (either using redirect or popup).

Parameters

ParameterTypeDescription

args

Omit<Extract<AuthParams, { type: "oauth"; }>, "type">

Authentication parameters omitting the type, which will be set to “oauth”

Returns

Promise<OauthProviderInfo>

A promise that resolves to an OauthProviderInfo object containing provider information and the ID token.


fetchConfig()

1protected fetchConfig(): Promise<SignerConfig>;

Defined in: account-kit/signer/src/base.ts:1882

Returns

Promise<SignerConfig>


getAuthDetails()

1getAuthDetails(): Promise<User>;

Defined in: account-kit/signer/src/base.ts:479

Gets the current logged in user If a user has an ongoing session, it will use that session and try to authenticate

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// throws if not logged in
15const user = await signer.getAuthDetails();

Returns

Promise<User>

the current user

Throws

if there is no user logged in

Implementation of

1SmartAccountAuthenticator.getAuthDetails;

getConfig()

1getConfig(): Promise<SignerConfig>;

Defined in: account-kit/signer/src/base.ts:1874

Returns the signer configuration while fetching it if it’s not already initialized.

Returns

Promise<SignerConfig>

A promise that resolves to the signer configuration


getMfaStatus()

1getMfaStatus(): object;

Defined in: account-kit/signer/src/base.ts:719

Gets the current MFA status

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const mfaStatus = signer.getMfaStatus();
15if (mfaStatus === AlchemyMfaStatus.REQUIRED) {
16 // Handle MFA requirement
17}

Returns

object

The current MFA status

NameType

mfaFactorId?

string

mfaRequired

boolean


getUser()

Unauthenticated call to look up a user’s organizationId by email or phone

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.getUser({ type: "email", value: "[email protected]" });

Param

the params to look up

Call Signature

1getUser(email): Promise<
2 | null
3 | {
4 orgId: string;
5}>;

Defined in: account-kit/signer/src/base.ts:752

Unauthenticated call to look up a user’s organizationId by email

Deprecated

Use getUser({ type: “email”, value: email }) instead

Example
1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.getUser("[email protected]");
Parameters
ParameterTypeDescription

email

string

the email to lookup

Returns

Promise< | null | { orgId: string; }>

the organization id for the user if they exist

Call Signature

1getUser(params): Promise<
2 | null
3 | {
4 orgId: string;
5}>;

Defined in: account-kit/signer/src/base.ts:777

Unauthenticated call to look up a user’s organizationId by email or phone

Example
1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const result = await signer.getUser({ type: "email", value: "[email protected]" });
Parameters
ParameterType

params

GetUserParams

Returns

Promise< | null | { orgId: string; }>

the organization id for the user if they exist


initConfig()

1protected initConfig(): Promise<SignerConfig>;

Defined in: account-kit/signer/src/base.ts:1864

Returns

Promise<SignerConfig>


listAuthMethods()

1listAuthMethods(): Promise<AuthMethods>;

Defined in: account-kit/signer/src/base.ts:1305

Retrieves a list of auth methods associated with the authenticated user.

Returns

Promise<AuthMethods>

A promise that resolves to an AuthMethods object containing the user’s email, OAuth providers, and passkeys.

Throws

Thrown if the user is not authenticated


on()

1on<E>(event, listener): () => void;

Defined in: account-kit/signer/src/base.ts:183

Allows you to subscribe to events emitted by the signer

Type Parameters

Type Parameter

E extends keyof AlchemySignerEvents

Parameters

ParameterTypeDescription

event

E

the event to subscribe to

listener

AlchemySignerEvents[E]

the function to run when the event is emitted

Returns

a function to remove the listener

1(): void;
Returns

void


preparePopupOauth()

1preparePopupOauth(): Promise<OauthConfig>;

Defined in: account-kit/signer/src/base.ts:285

Prepares the config needed to use popup-based OAuth login. This must be called before calling .authenticate with params { type: "oauth", mode: "popup" }, and is recommended to be called on page load.

This method exists because browsers may prevent popups from opening unless triggered by user interaction, and so the OAuth config must already have been fetched at the time a user clicks a social login button.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14await signer.preparePopupOauth();

Returns

Promise<OauthConfig>

the config which must be loaded before using popup-based OAuth


removeOauthProvider()

1removeOauthProvider(providerId): Promise<any>;

Defined in: account-kit/signer/src/base.ts:1292

Removes an OAuth provider by its ID if the user is authenticated.

Parameters

ParameterTypeDescription

providerId

string

The ID of the OAuth provider to be removed, as obtained from listOauthProviders

Returns

Promise<any>

A promise indicating the result of the removal process

Throws

Thrown if the user is not authenticated


setEmail()

Implementation for setEmail method.

Param

An object containing the verificationCode (or simply an email for legacy usage)

Call Signature

1setEmail(email): Promise<string>;

Defined in: account-kit/signer/src/base.ts:842

Sets the email for the authenticated user, allowing them to login with that email.

Deprecated

You must contact Alchemy to enable this feature for your team, as there are important security considerations. In particular, you must not call this without first validating that the user owns this email account. It is recommended to now use the email verification flow instead.

Parameters
ParameterTypeDescription

email

string

The email to set for the user

Returns

Promise<string>

A promise that resolves to the updated email address

Throws

If the user is not authenticated

Call Signature

1setEmail(params): Promise<string>;

Defined in: account-kit/signer/src/base.ts:854

Uses a verification code to update a user’s email, allowing them to login with that email. sendVerificationCode should be called first to obtain the code.

Parameters
ParameterTypeDescription

params

VerificationParams

An object containing the verification code

Returns

Promise<string>

A promise that resolves to the updated email address

Throws

If the user is not authenticated


toSolanaSigner()

1toSolanaSigner(): SolanaSigner;

Defined in: account-kit/signer/src/base.ts:1123

Creates a new instance of SolanaSigner using the provided inner value. This requires the signer to be authenticated first

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const solanaSigner = signer.toSolanaSigner();

Returns

SolanaSigner

A new instance of SolanaSigner


toViemAccount()

1toViemAccount(): object;

Defined in: account-kit/signer/src/base.ts:1079

This method lets you adapt your AlchemySigner to a viem LocalAccount, which will let you use the signer as an EOA directly.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14const account = signer.toViemAccount();

Returns

object

a LocalAccount object that can be used with viem’s wallet client

NameType

address

`0x${string}`

nonceManager?

NonceManager

publicKey

`0x${string}`

sign()?

(parameters) => Promise<`0x${string}`>

signAuthorization()?

(parameters) => Promise<SignAuthorizationReturnType>

signMessage()

(__namedParameters) => Promise<`0x${string}`>

signTransaction()

<serializer, transaction>(transaction, options?) => Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, `0x${string}`> extends true ? TransactionSerialized<GetTransactionType<transaction>> : `0x${string}`>

signTypedData()

<typedData, primaryType>(parameters) => Promise<`0x${string}`>

source

string

type

"local"

Throws

if your signer is not authenticated


validateMultiFactors()

1validateMultiFactors(params): Promise<User>;

Defined in: account-kit/signer/src/base.ts:1805

Validates MFA factors that were required during authentication. This function should be called after MFA is required and the user has provided their MFA code. It completes the authentication process by validating the MFA factors and completing the auth bundle.

Example

1import { AlchemyWebSigner } from "@account-kit/signer";
2
3const signer = new AlchemyWebSigner({
4 client: {
5 connection: {
6 rpcUrl: "/api/rpc",
7 },
8 iframeConfig: {
9 iframeContainerId: "alchemy-signer-iframe-container",
10 },
11 },
12});
13
14// After MFA is required and user provides code
15const user = await signer.validateMultiFactors({
16 multiFactorCode: "123456", // 6-digit code from authenticator app
17 multiFactorId: "factor-id",
18});

Parameters

ParameterTypeDescription

params

ValidateMultiFactorsArgs

Parameters for validating MFA factors

Returns

Promise<User>

A promise that resolves to the authenticated user

Throws

If there is no pending MFA context or if orgId is not found