Alchemy Logo

AlchemyWebSigner

Defined in: account-kit/signer/src/signer.ts:122

A SmartAccountSigner that can be used with any SmartContractAccount

new AlchemyWebSigner(params): AlchemyWebSigner;

Defined in: account-kit/signer/src/signer.ts:146

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

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});

Parameters

ParameterTypeDescription

params

{ client: | AlchemySignerWebClient | { connection: | { apiKey: string; jwt?: undefined; rpcUrl?: undefined; } | { apiKey?: undefined; jwt: string; rpcUrl?: undefined; } | { apiKey?: undefined; jwt?: undefined; rpcUrl: string; } | { apiKey?: undefined; jwt: string; rpcUrl: string; } & object; enablePopupOauth?: boolean; iframeConfig: { iframeContainerId: string; iframeElementId?: string; }; oauthCallbackUrl?: string; rootOrgId?: string; rpId?: string; }; sessionConfig?: { expirationTimeMs?: number; sessionKey?: string; storage?: "localStorage" | "sessionStorage" | Storage; }; }

The parameters for the Alchemy signer, including the client and session configuration

params.client

| AlchemySignerWebClient | { connection: | { apiKey: string; jwt?: undefined; rpcUrl?: undefined; } | { apiKey?: undefined; jwt: string; rpcUrl?: undefined; } | { apiKey?: undefined; jwt?: undefined; rpcUrl: string; } | { apiKey?: undefined; jwt: string; rpcUrl: string; } & object; enablePopupOauth?: boolean; iframeConfig: { iframeContainerId: string; iframeElementId?: string; }; oauthCallbackUrl?: string; rootOrgId?: string; rpId?: string; }

params.sessionConfig?

{ expirationTimeMs?: number; sessionKey?: string; storage?: "localStorage" | "sessionStorage" | Storage; }

params.sessionConfig.expirationTimeMs?

number

params.sessionConfig.sessionKey?

string

params.sessionConfig.storage?

"localStorage" | "sessionStorage" | Storage

Returns

AlchemyWebSigner

Overrides

BaseAlchemySigner.constructor

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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const result = await signer.addMfa({ multiFactorType: "totp" });
// 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const result = await signer.authenticate({
 type: "email",
 email: "[email protected]",
});

disconnect

() => Promise<void>

undefined

Clear a user session and log them out

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
await signer.disconnect();

exportPrivateKeyEncrypted

(opts) => Promise<ExportPrivateKeyEncryptedResult>

undefined

Exports a private key for a given account encrypted with the provided public key

Param

the parameters for the export

exportWallet

(config) => Promise<boolean>

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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
// the params passed to this are different based on the specific signer
const 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const { multiFactors } = await signer.getMfaFactors();

Throws

If no user is authenticated

getPasskeyStatus

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

undefined

inner

AlchemySignerWebClient

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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const result = await signer.removeMfa({
  multiFactorIds: ["factor-id-1", "factor-id-2"]
});

Throws

If no user is authenticated

removePasskey

(authenticatorId) => Promise<void>

undefined

Removes a passkey from a user's account

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const authMethods = await signer.listAuthMethods();
const passkey = authMethods.passkeys[0];
 
const 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 { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const tx = await signer.signAuthorization({
 contractAddress: "0x1234123412341234123412341234123412341234",
 chainId: 1,
 nonce: 0,
});

signerType

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

"alchemy-signer"

signMessage

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

undefined

Signs a raw message after hashing it.

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const tx = await signer.signTransaction({
 to: "0x1234",
 value: "0x1234",
 data: "0x1234",
});

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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const signature = await signer.signTypedData({
 domain: {},
 types: {},
 primaryType: "",
 message: {},
});

verifyMfa

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

undefined

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

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
 client: {
   connection: {
     rpcUrl: "/api/rpc",
   },
   iframeConfig: {
     iframeContainerId: "alchemy-signer-iframe-container",
   },
 },
});
 
const result = await signer.verifyMfa({
  multiFactorId: "factor-id",
  multiFactorCode: "123456" // 6-digit code from authenticator app
});

Throws

If no user is authenticated

addOauthProvider(args): Promise<OauthProviderInfo>;

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

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.

Inherited from

BaseAlchemySigner.addOauthProvider


protected fetchConfig(): Promise<SignerConfig>;

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

Returns

Promise<SignerConfig>

Inherited from

BaseAlchemySigner.fetchConfig


getAuthDetails(): 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
// throws if not logged in
const user = await signer.getAuthDetails();

Returns

Promise<User>

the current user

Throws

if there is no user logged in

Inherited from

BaseAlchemySigner.getAuthDetails


getConfig(): Promise<SignerConfig>;

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

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

Returns

Promise<SignerConfig>

A promise that resolves to the signer configuration

Inherited from

BaseAlchemySigner.getConfig


getMfaStatus(): object;

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

Gets the current MFA status

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const mfaStatus = signer.getMfaStatus();
if (mfaStatus === AlchemyMfaStatus.REQUIRED) {
  // Handle MFA requirement
}

Returns

object

The current MFA status

NameType

mfaFactorId?

string

mfaRequired

boolean

Inherited from

BaseAlchemySigner.getMfaStatus


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

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const result = await signer.getUser({ type: "email", value: "[email protected]" });

Param

the params to look up

Call Signature

getUser(email): Promise<
  | null
  | {
  orgId: string;
}>;

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
import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const 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

Inherited from

BaseAlchemySigner.getUser

Call Signature

getUser(params): Promise<
  | null
  | {
  orgId: string;
}>;

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

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

Example
import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const 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

Inherited from

BaseAlchemySigner.getUser


protected initConfig(): Promise<SignerConfig>;

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

Returns

Promise<SignerConfig>

Inherited from

BaseAlchemySigner.initConfig


listAuthMethods(): Promise<AuthMethods>;

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

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

Inherited from

BaseAlchemySigner.listAuthMethods


on<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

(): void;
Returns

void

Inherited from

BaseAlchemySigner.on


preparePopupOauth(): 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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
await signer.preparePopupOauth();

Returns

Promise<OauthConfig>

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

Inherited from

BaseAlchemySigner.preparePopupOauth


removeOauthProvider(providerId): Promise<any>;

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

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

Inherited from

BaseAlchemySigner.removeOauthProvider


Implementation for setEmail method.

Param

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

Call Signature

setEmail(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

Inherited from

BaseAlchemySigner.setEmail

Call Signature

setEmail(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

Inherited from

BaseAlchemySigner.setEmail


toSolanaSigner(): SolanaSigner;

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

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

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const solanaSigner = signer.toSolanaSigner();

Returns

SolanaSigner

A new instance of SolanaSigner

Inherited from

BaseAlchemySigner.toSolanaSigner


toViemAccount(): object;

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

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

Example

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
const 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<`0x${string}`>

signTypedData()

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

source

string

type

"local"

Throws

if your signer is not authenticated

Inherited from

BaseAlchemySigner.toViemAccount


validateMultiFactors(params): Promise<User>;

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

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

import { AlchemyWebSigner } from "@account-kit/signer";
 
const signer = new AlchemyWebSigner({
  client: {
    connection: {
      rpcUrl: "/api/rpc",
    },
    iframeConfig: {
      iframeContainerId: "alchemy-signer-iframe-container",
    },
  },
});
 
// After MFA is required and user provides code
const user = await signer.validateMultiFactors({
  multiFactorCode: "123456", // 6-digit code from authenticator app
  multiFactorId: "factor-id",
});

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

Inherited from

BaseAlchemySigner.validateMultiFactors

Was this page helpful?