> ## 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.

# EventLog.getIndexedTopics

> Get indexed parameters (topic1-topic3)

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/event-log.ts">
  Run EventLog examples in the interactive playground
</Card>

<Tabs />

## Indexed Parameter Limits

Solidity events can have maximum 3 indexed parameters (topic1-topic3):

```solidity theme={null}
// Maximum indexed parameters
event MaxIndexed(
  address indexed param1,
  address indexed param2,
  uint256 indexed param3,
  uint256 param4  // Not indexed (in data)
) /* anonymous */;
```

Anonymous events can have 4 indexed parameters (topic0-topic3):

```solidity theme={null}
event AnonymousEvent(
  address indexed param1,
  address indexed param2,
  uint256 indexed param3,
  uint256 indexed param4
) anonymous;
```

## Usage Patterns

### Extracting Transfer Parameters

```typescript theme={null}
import { EventLog, Address, Hash } from 'tevm';

// Transfer(address indexed from, address indexed to, uint256 value)
const TRANSFER_SIG = Hash('0xddf252ad...');

function decodeTransfer(log: EventLog) {
  const sig = log.getTopic0();
  if (!sig || !Hash.equals(sig, TRANSFER_SIG)) {
    throw new Error('Not a Transfer event');
  }

  const [fromHash, toHash] = log.getIndexedTopics();

  // Extract addresses from topic hashes (last 20 bytes)
  const from = Address(fromHash.slice(12));
  const to = Address(toHash.slice(12));

  // Decode value from data
  const value = new DataView(log.data.buffer).getBigUint64(24, false);

  return { from, to, value };
}

const transfer = decodeTransfer(transferLog);
console.log('From:', Address.toHex(transfer.from));
console.log('To:', Address.toHex(transfer.to));
console.log('Value:', transfer.value);
```

### Validating Parameter Count

```typescript theme={null}
import { EventLog } from 'tevm';

function validateEventStructure(log: EventLog, expectedCount: number): boolean {
  const indexed = log.getIndexedTopics();

  if (indexed.length !== expectedCount) {
    console.error(
      `Expected ${expectedCount} indexed params, got ${indexed.length}`
    );
    return false;
  }

  return true;
}

// Transfer has 2 indexed parameters (from, to)
validateEventStructure(transferLog, 2); // true

// Approval has 2 indexed parameters (owner, spender)
validateEventStructure(approvalLog, 2); // true
```

### Destructuring Parameters

```typescript theme={null}
import { EventLog } from 'tevm';

// Approval(address indexed owner, address indexed spender, uint256 value)
const log = EventLog({ /* ... */ });

const [ownerHash, spenderHash] = log.getIndexedTopics();

console.log('Owner:', Hash.toHex(ownerHash));
console.log('Spender:', Hash.toHex(spenderHash));
```

### Empty Indexed Topics

```typescript theme={null}
import { EventLog, Address, Hash } from 'tevm';

// Event with no indexed parameters
const log = EventLog({
  address: contractAddress,
  topics: [Hash('0xeventSig...')], // Only signature
  data: eventData,
});

const indexed = log.getIndexedTopics();
console.log(indexed.length); // 0 (empty array)
```

### Anonymous Event Handling

```typescript theme={null}
import { EventLog } from 'tevm';

// Anonymous events: topic0 is first indexed param, NOT signature
const anonymousLog = EventLog({
  address: contractAddress,
  topics: [param1Hash, param2Hash, param3Hash], // All indexed params
  data: Bytes(),
});

// getIndexedTopics returns topic1-topic3 (NOT all params)
const indexed = anonymousLog.getIndexedTopics();
console.log(indexed.length); // 2 (param2 and param3)

// To get ALL indexed params from anonymous event:
const allParams = [anonymousLog.getTopic0(), ...indexed].filter(Boolean);
console.log(allParams.length); // 3
```

## Extracting Addresses from Topics

Addresses in topics are left-padded to 32 bytes. Extract the address by taking the last 20 bytes:

```typescript theme={null}
import { Address, Hash } from 'tevm';

const topicHash = Hash('0x000000000000000000000000a1b2c3d4e5f67890abcdef1234567890abcdef12');

// Extract address (last 20 bytes)
const address = Address(topicHash.slice(12));

console.log(Address.toHex(address));
// '0xa1b2c3d4e5f67890abcdef1234567890abcdef12'
```

## See Also

* [getIndexed](/primitives/eventlog/getindexed) - Alias for getIndexedTopics
* [getTopic0](/primitives/eventlog/gettopic0) - Get event signature
* [Fundamentals](/primitives/eventlog/fundamentals) - Topics and indexed parameters
