> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Get Transaction Count \[block.getTransactionCount]

Returns the number of transactions at a block number, hash, or tag.

## Usage

This example returns the number of transactions at a block number, hash, or tag.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const count = await client.block.getTransactionCount()
// @log: 123
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())
```
:::

### Standalone Action

Call `Actions.block.getTransactionCount` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const count = await Actions.block.getTransactionCount(client)
// @log: 123
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Recipes

### Count Transactions by Block Hash

Pass `blockHash` when the exact block hash is already known.

```ts twoslash
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())

const count = await client.block.getTransactionCount({
  blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', // [!code focus]
})
```

### Count Transactions at a Block Number

Pass `blockNumber` to count transactions in a historical block.

```ts twoslash
import { Client, http, publicActions } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({
  chain: mainnet,
  transport: http(),
}).extend(publicActions())

const count = await client.block.getTransactionCount({
  blockNumber: 19_868_020n, // [!code focus]
})
```

## Return Value

`number`

The number of transactions in the block.

## Parameters

### blockHash

* **Type:** `Hex`

The number of transactions at a given block hash.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const count = await Actions.block.getTransactionCount(client, {
  blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d', // [!code focus]
})
```

### blockNumber

* **Type:** `bigint`

The number of transactions at a given block number.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const count = await Actions.block.getTransactionCount(client, {
  blockNumber: 42069n, // [!code focus]
})
```

### blockTag

* **Type:** `'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'`
* **Default:** `'latest'`

The number of transactions at a given block tag.

```ts twoslash
import { Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const count = await Actions.block.getTransactionCount(client, {
  blockTag: 'safe', // [!code focus]
})
```
