Skip to content

Send a transaction with viem

toViemAccount adapts a signing session into the account shape viem accepts, so viem signs and broadcasts while the session owns the key.

import {
function getPasskeyPrfOutput({ rpId, credential: allowCredential, prfSalt, timeout, immediate, webAuthnClient, }: getPasskeyPrfOutput.Options): Promise<getPasskeyPrfOutput.Result>

Requests a passkey PRF evaluation and returns the first output.

@param ― options - Passkey PRF request inputs.

@returns ― The selected credential ID and first WebAuthn PRF output.

@remarks ―

Runs one assertion ceremony and shows one user-verification prompt.

With immediate, Chrome 148 and later (as of 2026-10) and the React Native client show nothing when the device holds no passkey for rpId. Browsers without immediate mode ignore the option and show their usual prompt. Without a user gesture, or in Incognito, Chrome rejects an immediate request with the same error even when a passkey exists.

The WebAuthn challenge is generated internally.

The default salt is sha256("mera.prf.salt.v1") and will not change across library versions. The PRF output is a deterministic function of the credential, rpId, and salt; a different salt yields an unrelated output.

The assertion requires user verification, and the requirement is not configurable. User verification is the authenticator's local check; the gesture depends on the platform (a biometric, a device PIN, or a password). Authenticators built on CTAP's hmac-secret keep two PRFs per credential, one for user-verified requests and one for the rest; WebAuthn exposes only the user-verified PRF and overrides a weaker userVerification setting when evaluating it, so a configurable setting could neither change the PRF output nor skip the check.

@see ― https://www.w3.org/TR/webauthn-3/#prf-extension WebAuthn: the PRF extension

@see ― https://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement WebAuthn: UserVerificationRequirement

@throws ― MeraError with code PRF_UNAVAILABLE when the authenticator does not return a usable 32-byte PRF output.

@throws ― MeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes, credential.credentialId is empty or not canonical base64url, or immediate is combined with credential.

@throws ― MeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throws ― MeraError with code PASSKEY_CANCELLED when the person dismisses the prompt, it times out, or no passkey answers, including an immediate request that finds none.

@throws ― MeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, fails for another reason, or returns an unexpected credential.

getPasskeyPrfOutput
} from "@category-labs/mera";
const
const rpId: string
rpId
=
var location: Location

The Window.location read-only property returns a Location object with information about the current location of the document.

MDN Reference

location
.
Location.hostname: string

The hostname property of the Location interface is a string containing either the domain name or IP address of the location URL.

MDN Reference

hostname
;
const {
const prfOutput: Uint8Array<ArrayBuffer>

First PRF output from WebAuthn. Always 32 bytes.

prfOutput
} = await
function getPasskeyPrfOutput({ rpId, credential: allowCredential, prfSalt, timeout, immediate, webAuthnClient, }: getPasskeyPrfOutput.Options): Promise<getPasskeyPrfOutput.Result>

Requests a passkey PRF evaluation and returns the first output.

@param ― options - Passkey PRF request inputs.

@returns ― The selected credential ID and first WebAuthn PRF output.

@remarks ―

Runs one assertion ceremony and shows one user-verification prompt.

With immediate, Chrome 148 and later (as of 2026-10) and the React Native client show nothing when the device holds no passkey for rpId. Browsers without immediate mode ignore the option and show their usual prompt. Without a user gesture, or in Incognito, Chrome rejects an immediate request with the same error even when a passkey exists.

The WebAuthn challenge is generated internally.

The default salt is sha256("mera.prf.salt.v1") and will not change across library versions. The PRF output is a deterministic function of the credential, rpId, and salt; a different salt yields an unrelated output.

The assertion requires user verification, and the requirement is not configurable. User verification is the authenticator's local check; the gesture depends on the platform (a biometric, a device PIN, or a password). Authenticators built on CTAP's hmac-secret keep two PRFs per credential, one for user-verified requests and one for the rest; WebAuthn exposes only the user-verified PRF and overrides a weaker userVerification setting when evaluating it, so a configurable setting could neither change the PRF output nor skip the check.

@see ― https://www.w3.org/TR/webauthn-3/#prf-extension WebAuthn: the PRF extension

@see ― https://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement WebAuthn: UserVerificationRequirement

@throws ― MeraError with code PRF_UNAVAILABLE when the authenticator does not return a usable 32-byte PRF output.

@throws ― MeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes, credential.credentialId is empty or not canonical base64url, or immediate is combined with credential.

@throws ― MeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throws ― MeraError with code PASSKEY_CANCELLED when the person dismisses the prompt, it times out, or no passkey answers, including an immediate request that finds none.

@throws ― MeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, fails for another reason, or returns an unexpected credential.

getPasskeyPrfOutput
({
rpId: string

Relying party ID for the WebAuthn assertion.

rpId
});

deriveEvmPrivateKey derives the key of the first EVM account.

import {
function deriveEvmPrivateKey({ prfOutput, accountIndex, }: DerivePrivateKeyOptions): Uint8Array<ArrayBuffer>

Derives the private key of an EVM account from a PRF output.

@param ― options - PRF output and account index.

@returns ― A 32-byte secp256k1 private key.

@remarks ―

The PRF output is the entropy of a 24-word BIP-39 phrase from the English wordlist, and the phrase's seed uses an empty passphrase. The key is the BIP-32 key at m/44'/60'/0'/0/{accountIndex} under that seed. Wallet apps such as MetaMask use the same path, so importing the phrase into one shows the same accounts.

The phrase exists as a JavaScript string, which cannot be zeroed, and @scure/bip32 leaves the intermediate keys and chain codes unzeroed.

@see ― https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki BIP-39

@see ― https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki BIP-32

@see ― https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki BIP-44

@throws ― MeraError with code INPUT_INVALID when prfOutput is not 32 bytes, or accountIndex is not an integer from 0 to 2^31 - 1.

deriveEvmPrivateKey
} from "@category-labs/mera";
const
const privateKey: Uint8Array<ArrayBuffer>
privateKey
=
function deriveEvmPrivateKey({ prfOutput, accountIndex, }: DerivePrivateKeyOptions): Uint8Array<ArrayBuffer>

Derives the private key of an EVM account from a PRF output.

@param ― options - PRF output and account index.

@returns ― A 32-byte secp256k1 private key.

@remarks ―

The PRF output is the entropy of a 24-word BIP-39 phrase from the English wordlist, and the phrase's seed uses an empty passphrase. The key is the BIP-32 key at m/44'/60'/0'/0/{accountIndex} under that seed. Wallet apps such as MetaMask use the same path, so importing the phrase into one shows the same accounts.

The phrase exists as a JavaScript string, which cannot be zeroed, and @scure/bip32 leaves the intermediate keys and chain codes unzeroed.

@see ― https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki BIP-39

@see ― https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki BIP-32

@see ― https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki BIP-44

@throws ― MeraError with code INPUT_INVALID when prfOutput is not 32 bytes, or accountIndex is not an integer from 0 to 2^31 - 1.

deriveEvmPrivateKey
({
prfOutput: Uint8Array<ArrayBufferLike>

PRF output used as the BIP-39 entropy. Must be exactly 32 bytes.

prfOutput
,
accountIndex: number

Account number in the derivation path, an integer from 0 to 2^31 - 1.

accountIndex
: 0 });

toViemAccount lives in the @category-labs/mera/viem entry point, which requires the optional viem peer dependency.

import {
function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession

Creates a signing session from a secp256k1 private key.

@param ― options - Signing session inputs.

@returns ― A live secp256k1 signing session.

@throws ― MeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

createSecp256k1SigningSession
} from "@category-labs/mera";
import {
function toViemAccount(session: Secp256k1SigningSession, { nonceManager }?: ToViemAccountOptions): LocalAccount<"mera">

Adapts a secp256k1 signing session into a viem local account.

Each signing method hashes its input with viem's own hashers and signs the resulting 32-byte digest with session.signDigest, so signing never shows a passkey prompt. The account's address is the EIP-55 checksummed address of the session key, and publicKey is the 65-byte uncompressed public key as hex.

@param ― session - Live secp256k1 signing session that backs the account.

@param ― options - Adapter inputs.

@returns ― A viem local account with source: "mera" implementing signTransaction (honoring a custom serializer), signMessage (EIP-191), signTypedData (EIP-712), signAuthorization (EIP-7702), and raw-hash sign.

@throws ― MeraError with code SESSION_ENDED, rejected from every signing method after session.end() has been called.

@throws ― MeraError with code INPUT_INVALID, rejected from sign when hash is not exactly 32 bytes.

toViemAccount
} from "@category-labs/mera/viem";
const
const session: Secp256k1SigningSession
session
=
function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession

Creates a signing session from a secp256k1 private key.

@param ― options - Signing session inputs.

@returns ― A live secp256k1 signing session.

@throws ― MeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

createSecp256k1SigningSession
({
privateKey: Uint8Array<ArrayBufferLike>

Curve private key. Must be exactly 32 bytes and, for secp256k1, a valid scalar.

privateKey
});
const
const account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign?: ((parameters: {
hash: Hash;
}) => Promise<Hex>) | undefined | undefined;
signAuthorization?: ((parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>) | undefined | undefined;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
... 4 more ...;
type: "local";
}
account
=
function toViemAccount(session: Secp256k1SigningSession, { nonceManager }?: ToViemAccountOptions): LocalAccount<"mera">

Adapts a secp256k1 signing session into a viem local account.

Each signing method hashes its input with viem's own hashers and signs the resulting 32-byte digest with session.signDigest, so signing never shows a passkey prompt. The account's address is the EIP-55 checksummed address of the session key, and publicKey is the 65-byte uncompressed public key as hex.

@param ― session - Live secp256k1 signing session that backs the account.

@param ― options - Adapter inputs.

@returns ― A viem local account with source: "mera" implementing signTransaction (honoring a custom serializer), signMessage (EIP-191), signTypedData (EIP-712), signAuthorization (EIP-7702), and raw-hash sign.

@throws ― MeraError with code SESSION_ENDED, rejected from every signing method after session.end() has been called.

@throws ― MeraError with code INPUT_INVALID, rejected from sign when hash is not exactly 32 bytes.

toViemAccount
(
const session: Secp256k1SigningSession
session
);
import {
function createWalletClient<transport extends Transport, chain extends Chain | undefined = undefined, accountOrAddress extends Account | Address | undefined = undefined, rpcSchema extends RpcSchema | undefined = undefined, const tokens extends Tokens | undefined = undefined>(parameters: WalletClientConfig<transport, chain, accountOrAddress, rpcSchema, tokens>): WalletClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema, tokens>

Creates a Wallet Client with a given Transport configured for a Chain.

A Wallet Client is an interface to interact with Ethereum Account(s) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through Wallet Actions.

The Wallet Client supports signing over:

@param ― config - WalletClientConfig

@returns ― A Wallet Client. WalletClient

@example

// JSON-RPC Account import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains'

const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), })

@example

// Local Account import { createWalletClient, custom } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains'

const client = createWalletClient({ account: privateKeyToAccount('0x…') chain: mainnet, transport: http(), })

createWalletClient
,
function http<rpcSchema extends RpcSchema | undefined = undefined, raw extends boolean = false>(url?: string | undefined, config?: HttpTransportConfig<rpcSchema, raw>): HttpTransport<rpcSchema, raw>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
,
function parseEther(ether: string, unit?: "wei" | "gwei"): bigint

Converts a string representation of ether to numerical wei.

@example

import { parseEther } from 'viem'

parseEther('420') // 420000000000000000000n

parseEther
} from "viem";
import {
const sepolia: {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://sepolia.etherscan.io";
readonly apiUrl: "https://api-sepolia.etherscan.io/api";
};
};
blockTime?: number | undefined | undefined;
contracts: {
readonly multicall3: {
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
readonly blockCreated: 751532;
};
readonly ensUniversalResolver: {
readonly address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
readonly blockCreated: 8928790;
};
};
... 16 more ...;
verifyHash?: ((client: Client<...>, parameters: VerifyHashParameters) => Promise<boolean>) | undefined;
}
sepolia
} from "viem/chains";
const
const client: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign?: ((parameters: {
hash: Hash;
}) => Promise<Hex>) | undefined | undefined;
signAuthorization?: ((parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>) | undefined | undefined;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
... 4 more ...;
type: "local";
};
... 44 more ...;
scope: (options?: {
signal?: AbortSignal | undefined;
} | undefined) => Client<...>;
}
client
=
createWalletClient<HttpTransport<undefined, false>, {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://sepolia.etherscan.io";
readonly apiUrl: "https://api-sepolia.etherscan.io/api";
};
};
blockTime?: number | undefined | undefined;
contracts: {
readonly multicall3: {
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
readonly blockCreated: 751532;
};
readonly ensUniversalResolver: {
readonly address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
readonly blockCreated: 8928790;
};
};
... 16 more ...;
verifyHash?: ((client: Client<...>, parameters: VerifyHashParameters) => Promise<boolean>) | undefined;
}, {
...;
}, undefined, undefined>(parameters: {
...;
}): {
...;
}

Creates a Wallet Client with a given Transport configured for a Chain.

A Wallet Client is an interface to interact with Ethereum Account(s) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through Wallet Actions.

The Wallet Client supports signing over:

@param ― config - WalletClientConfig

@returns ― A Wallet Client. WalletClient

@example

// JSON-RPC Account import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains'

const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), })

@example

// Local Account import { createWalletClient, custom } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains'

const client = createWalletClient({ account: privateKeyToAccount('0x…') chain: mainnet, transport: http(), })

createWalletClient
({
account?: `0x${string}` | Account | {
address: Address;
nonceManager?: NonceManager | undefined;
sign?: ((parameters: {
hash: Hash;
}) => Promise<Hex>) | undefined | undefined;
signAuthorization?: ((parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>) | undefined | undefined;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
... 4 more ...;
type: "local";
} | undefined

The Account to use for the Client. This will be used for Actions that require an account as an argument.

account
,
chain?: Chain | {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://sepolia.etherscan.io";
readonly apiUrl: "https://api-sepolia.etherscan.io/api";
};
};
blockTime?: number | undefined | undefined;
contracts: {
readonly multicall3: {
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
readonly blockCreated: 751532;
};
readonly ensUniversalResolver: {
readonly address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
readonly blockCreated: 8928790;
};
};
... 16 more ...;
verifyHash?: ((client: Client<...>, parameters: VerifyHashParameters) => Promise<boolean>) | undefined;
} | undefined

Chain for the client.

chain
:
const sepolia: {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://sepolia.etherscan.io";
readonly apiUrl: "https://api-sepolia.etherscan.io/api";
};
};
blockTime?: number | undefined | undefined;
contracts: {
readonly multicall3: {
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
readonly blockCreated: 751532;
};
readonly ensUniversalResolver: {
readonly address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
readonly blockCreated: 8928790;
};
};
... 16 more ...;
verifyHash?: ((client: Client<...>, parameters: VerifyHashParameters) => Promise<boolean>) | undefined;
}
sepolia
,
transport: HttpTransport<undefined, false>

The RPC transport

transport
:
http<undefined, false>(url?: string | undefined, config?: HttpTransportConfig<undefined, false> | undefined): HttpTransport<undefined, false>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
(),
});
const
const recipient: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
recipient
= "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
const
const hash: `0x${string}`
hash
= await
const client: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign?: ((parameters: {
hash: Hash;
}) => Promise<Hex>) | undefined | undefined;
signAuthorization?: ((parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>) | undefined | undefined;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
... 4 more ...;
type: "local";
};
... 44 more ...;
scope: (options?: {
signal?: AbortSignal | undefined;
} | undefined) => Client<...>;
}
client
.
sendTransaction: <{
readonly to: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
readonly value: bigint;
}, undefined>(args: SendTransactionParameters<{
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://sepolia.etherscan.io";
readonly apiUrl: "https://api-sepolia.etherscan.io/api";
};
};
blockTime?: number | undefined | undefined;
contracts: {
readonly multicall3: {
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
readonly blockCreated: 751532;
};
readonly ensUniversalResolver: {
readonly address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee";
readonly blockCreated: 8928790;
};
};
... 16 more ...;
verifyHash?: ((client: Client<...>, parameters: VerifyHashParameters) => Promise<boolean>) | undefined;
}, {
...;
}, undefined, {
readonly to: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
readonly value: bigint;
}>) => Promise<SendTransactionReturnType>

Creates, signs, and sends a new transaction to the network.

@param ― args - SendTransactionParameters

@returns ― The Transaction hash. SendTransactionReturnType

@example

import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains'

const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), }) const hash = await client.sendTransaction({ account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n, })

@example

// Account Hoisting import { createWalletClient, http } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains'

const client = createWalletClient({ account: privateKeyToAccount('0x…'), chain: mainnet, transport: http(), }) const hash = await client.sendTransaction({ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n, })

sendTransaction
({
to: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
to
:
const recipient: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
recipient
,
value: bigint
value
:
function parseEther(ether: string, unit?: "wei" | "gwei"): bigint

Converts a string representation of ether to numerical wei.

@example

import { parseEther } from 'viem'

parseEther('420') // 420000000000000000000n

parseEther
("0.01"),
});
const session: Secp256k1SigningSession
session
.
function end(): void

Zeroes the session-owned private-key copy; later signing throws SESSION_ENDED.

end
();

sendTransaction fills the missing transaction fields from the RPC, signs through the session and broadcasts.