Skip to content
On this page

getTransactionCount โ€‹

Returns the number of Transactions an Account has broadcast / sent.

Usage โ€‹

ts
import { publicClient } from './client'

const transactionCount = await publicClient.getTransactionCount({  
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
})
// 420
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})

Returns โ€‹

number

The number of transactions an account has sent.

Parameters โ€‹

address โ€‹

The address of the account.

ts
const transactionCount = await publicClient.getTransactionCount({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', 
})

blockNumber โ€‹

  • Type: bigint

Get the count at a block number.

ts
const transactionCount = await publicClient.getTransactionCount({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockNumber: 69420n  
})

blockTag โ€‹

  • Type: bigint

Get the count at a block tag.

ts
const transactionCount = await publicClient.getTransactionCount({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockTag: 'safe'  
})

Notes โ€‹

  • The transaction count of an account can also be used as a nonce.

Example โ€‹

JSON-RPC Method โ€‹

eth_getTransactionCount

Released under the MIT License.