Skip to content

getAccountNonce

Returns the current nonce of the smart account for a specified key.

Usage

example.ts
import { publicClient } from "./client.ts"
import { getAccountNonce, ENTRYPOINT_ADDRESS_V07 } from "permissionless"
 
const nonce = await getAccountNonce(publicClient, {
    address: "0x277F6C1D8d4faFA3d8DcC837489cd69d86c682BA",
    entryPoint: ENTRYPOINT_ADDRESS_V07,
    key: 0n // optional
})
// 23n

Returns

  • Type: bigint

The current nonce of the smart account for the specified key (both the key and the sequence concatenated together into one uint256).

Parameters

address

  • Type: Address

The address of the smart account.

entryPoint

  • Type: Address

The entry point address.

key (optional)

  • Type: bigint

The key of the nonce. Defaults to 0n.

Instead of sequential nonce, ERC-4337 implements a nonce mechanism that uses a single uint256 nonce value in the UserOperation, but treats it as two values, a 192-bit “key”, and a 64-bit “sequence”. These values are represented on-chain in the EntryPoint contract. For each key the sequence is validated and incremented sequentially and monotonically by the EntryPoint for each UserOperation, however a new key can be introduced with an arbitrary value at any point.