Skip to content
Get startedGetting started →

toViemAccount

Adapts a secp256k1 signing session into a viem local account. Every signing method signs through session.signDigest, so signing shows no passkey prompt. The function lives in the @category-labs/mera/viem entry point, which requires viem (^2.28.0) as an optional peer dependency; the root entry point does not use viem.

import { toViemAccount } from "@category-labs/mera/viem";
import { createSecp256k1SigningSession } from "@category-labs/mera";
import { toViemAccount } from "@category-labs/mera/viem";
import { createWalletClient, http, parseEther } from "viem";
import { sepolia } from "viem/chains";
const privateKey = crypto.getRandomValues(new Uint8Array(32));
const session = createSecp256k1SigningSession({ privateKey });
const client = createWalletClient({
account: toViemAccount(session),
chain: sepolia,
transport: http(),
});
const recipient = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
const hash = await client.sendTransaction({
to: recipient,
value: parseEther("0.01"),
});
session.end();

The session is positional; options is a ToViemAccountOptions and may be omitted.

Live secp256k1 signing session that backs the account. createSecp256k1SigningSession produces one.

  • Type: NonceManager, from viem
  • Optional; when omitted the account carries no nonce manager

viem nonce manager forwarded to the account. viem clients use it to assign transaction nonces automatically.

A viem LocalAccount with source: "mera", accepted anywhere viem takes an account.

The EIP-55 checksummed address of the session key, the same value getEvmAddress returns for session.publicKey.

The 65-byte uncompressed secp256k1 public key as hex: the 0x04 prefix, then 128 hex characters.

Serializes the transaction, signs its keccak-256 digest, and resolves to the signed serialized transaction. options.serializer replaces viem’s serializeTransaction for both steps. EIP-4844 transactions are hashed without their sidecars and serialized with them.

Resolves to the EIP-191 personal-message signature for message, 65 bytes as hex.

Resolves to the EIP-712 signature for the typed data, 65 bytes as hex.

Signs an EIP-7702 authorization and resolves to the signed authorization object: the contract address, chain ID, and nonce together with the signature fields.

Signs a 32-byte hash directly, with no additional hashing, and resolves to the 65-byte hex signature.

  • SESSION_ENDED: any signing method rejects with this after session.end().
  • INPUT_INVALID: sign rejects with this when hash is not exactly 32 bytes.

Signatures are low-S, which EVM chains require since EIP-2.