Get Nonce
nonce.get
Gets the nonce for an account and nonce key.
Nonce key 0 is reserved for protocol nonces. Use keys greater than 0 for 2D nonces.
Usage
import { } from './viem.config'
const = await ..({
: 1n,
})
.('Nonce:', )
Nonce: 42nimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Prepare a Transaction on a Dedicated Lane
Read the lane's current nonce and pass both nonce and nonceKey to transaction.prepare, since the node does not fill keyed nonces for manually prepared requests.
import { } from './viem.config'
const = 7n // this worker's payout lane
const = await ..({ })
const { } = await ..({
: '0xcafebabe00000000000000000000000000000001',
: (),
,
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Reconcile Dispatched Payouts from a Monitor
Pass account to audit a lane of an account you do not sign for, such as a payout dispatcher's hot wallet: a lane's nonce counts its confirmed transactions.
import { } from './viem.config'
const = 45n // payouts submitted, from your job queue
const = await ..({
: '0x8ba1f109551bD432803012645Ac136ddd64DBA72',
: 7n,
})
.(`${ - } payouts pending`)
3 payouts pendingimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = bigintThe nonce value for the account and nonce key.
Parameters
account
- Type:
Account | Address - Default:
client.account
Account to read the nonce of. Defaults to the Client's account.
nonceKey
- Type:
bigint
Nonce key to read. Key 0 is reserved for protocol nonces.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.