> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# TransactionIndex

> Transaction position in block (0-based)

## Overview

TransactionIndex is a branded `number` type representing a transaction's position within a block. Indices start at 0 for the first transaction in a block.

```typescript theme={null}
import * as TransactionIndex from '@tevm/primitives/TransactionIndex'

const index = TransactionIndex.from(5)
```

## Type Definition

```typescript theme={null}
type TransactionIndexType = number & {
  readonly [brand]: "TransactionIndex";
}
```

## Creating TransactionIndexes

### from

Create from number or bigint.

```typescript theme={null}
// From number
const idx1 = TransactionIndex.from(5)

// From bigint
const idx2 = TransactionIndex.from(5n)

// First transaction in block
const first = TransactionIndex.from(0)
```

**Validation**: Must be non-negative integer.

## Converting TransactionIndexes

### toNumber

Convert to number (zero-cost).

```typescript theme={null}
const num = TransactionIndex.toNumber(index)
// 5
```

## Comparing TransactionIndexes

### equals

Check equality.

```typescript theme={null}
const a = TransactionIndex.from(5)
const b = TransactionIndex.from(5)

if (TransactionIndex.equals(a, b)) {
  console.log('Indexes are equal')
}
```

## Usage in Receipts

TransactionIndex appears in transaction receipts to indicate position within a block:

```typescript theme={null}
import * as Receipt from '@tevm/primitives/Receipt'

const receipt = Receipt.from({
  transactionIndex: TransactionIndex.from(3),
  // ... other fields
})
```

## Errors

**InvalidTransactionIndexError**: Invalid value (negative, non-integer, wrong type).

## See Also

* [Receipt](/primitives/receipt) - Transaction receipts
* [LogIndex](/primitives/log-index) - Log position
* [TransactionHash](/primitives/transaction-hash) - Transaction identifier
