Skip to content

getNonce

Action for getting a Starknet account's current nonce.

Import

import { getNonce } from "starkweb/core";

Usage

index.ts
import { getNonce } from "starkweb/core";
import { config } from "./config";
 
const nonce = await getNonce(config, {
  address: "0x123...", 
});

Parameters

import { type GetNonceParameters } from "starkweb/core";

address

Hex

The address of the account to get the nonce for.

index.ts
import { getNonce } from "starkweb/core";
import { config } from "./config";
 
const nonce = await getNonce(config, {
  address: "0x123...", 
});

chainId (optional)

Hex | undefined

The chain ID to get the nonce from. If not provided, uses the current chain.

index.ts
import { getNonce } from "starkweb/core";
import { mainnet } from "starkweb/chains"; 
import { config } from "./config";
 
const nonce = await getNonce(config, {
  address: "0x123...",
  chainId: mainnet.chain_id, 
});

Return Type

import { type GetNonceReturnType } from "starkweb/core";

Returns the nonce information including:

nonce

bigint

The current nonce of the account.

chainId

Hex

The chain ID of the network.

Example

example.ts
import { getNonce } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains"; 
import { config } from "./config";
 
// Get nonce on current chain
const currentNonce = await getNonce(config, {
  address: "0x123...", 
});
console.log("Current nonce:", currentNonce.nonce);
 
// Get nonce on specific chain
const mainnetNonce = await getNonce(config, {
  address: "0x123...",
  chainId: mainnet.chain_id, 
});

Error

import { type GetNonceErrorType } from "starkweb/core";