getBlockTransactionCount
Returns the number of Transactions at a block number, hash or tag.
Usage
ts
import { publicClient } from './client'
const count = await publicClient.getBlockTransactionCount()
// 23
import { publicClient } from './client'
const count = await publicClient.getBlockTransactionCount()
// 23
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
Returns
number
The block transaction count.
Parameters
blockHash (optional)
- Type:
Hash
Count at a given block hash.
ts
const count = await publicClient.getBlockTransactionCount({
blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d'
})
const count = await publicClient.getBlockTransactionCount({
blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d'
})
blockNumber (optional)
- Type:
bigint
Count at a given block number.
ts
const block = await publicClient.getBlockTransactionCount({
blockNumber: 42069n
})
const block = await publicClient.getBlockTransactionCount({
blockNumber: 42069n
})
blockTag (optional)
- Type:
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
- Default:
'latest'
Count at a given block tag.
ts
const block = await publicClient.getBlockTransactionCount({
blockTag: 'safe'
})
const block = await publicClient.getBlockTransactionCount({
blockTag: 'safe'
})
JSON-RPC Method
- Calls
eth_getBlockTransactionCountByNumber
forblockNumber
&blockTag
. - Calls
eth_getBlockTransactionCountByHash
forblockHash
.