> **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 \[transaction.get]

Returns information about a transaction given a hash or block identifier.

## Usage

This example returns information about a transaction given a hash or block identifier.

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

const transaction = await client.transaction.get({
  hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
// @log: {
// @log:   blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d',
// @log:   blockNumber: 19868020n,
// @log:   from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e',
// @log:   gas: 100000n,
// @log:   hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
// @log:   nonce: 16n,
// @log:   to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da',
// @log:   type: 'eip1559',
// @log:   value: 0n,
// @log:   ...
// @log: }
```

```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.transaction.get` 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 transaction = await Actions.transaction.get(client, {
  hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
// @log: {
// @log:   blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d',
// @log:   blockNumber: 19868020n,
// @log:   from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e',
// @log:   gas: 100000n,
// @log:   hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
// @log:   nonce: 16n,
// @log:   to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da',
// @log:   type: 'eip1559',
// @log:   value: 0n,
// @log:   ...
// @log: }
```

```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

### Get a Transaction from a Historical Block

Pass `blockNumber` and `index` to select a transaction by its position 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 transaction = await client.transaction.get({
  blockNumber: 19_868_020n, // [!code focus]
  index: 0, // [!code focus]
})
```

### Get a Pending Transaction

Pass the `pending` block tag and an index to read a transaction from the node's pending 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 transaction = await client.transaction.get({
  blockTag: 'pending', // [!code focus]
  index: 0, // [!code focus]
})
```

## Return Value

`Transaction`

Information about the transaction. When the connected Client's [`chain`](/docs/chains) defines a `codecs.transaction` codec, the return type reflects that chain's custom transaction shape.

## Parameters

### blockHash

* **Type:** `Hex`

Get a transaction by its index within the block of the given hash. Requires [`index`](#index).

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

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

### blockNumber

* **Type:** `bigint`

Get a transaction by its index within the block of the given number. Requires [`index`](#index).

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

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

### blockTag

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

Get a transaction by its index within the block of the given tag. Requires [`index`](#index).

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

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

### hash

* **Type:** `Hex`

Get a transaction by its hash.

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

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const transaction = await Actions.transaction.get(client, {
  hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', // [!code focus]
})
```

### index

* **Type:** `number`

The index of the transaction within a block. Used together with [`blockHash`](#blockhash), [`blockNumber`](#blocknumber), or [`blockTag`](#blocktag).

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

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

### nonce

* **Type:** `number`

Get a transaction by the [`sender`](#sender)'s nonce. Requires [`sender`](#sender).

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

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const transaction = await Actions.transaction.get(client, {
  sender: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e',
  nonce: 16, // [!code focus]
})
```

### sender

* **Type:** `Address`

Get a transaction by the sending account's address and [`nonce`](#nonce). Requires [`nonce`](#nonce).

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

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const transaction = await Actions.transaction.get(client, {
  sender: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e', // [!code focus]
  nonce: 16, // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Actions.transaction.Errors.TransactionNotFoundError` | The transaction could not be found. |
