EventTopics

Storage Map v101 → current

Map of event topics to event indices.

Explore chain
Queried by: developersanalytics

The Big Picture

Allows finding events by their topic (usually event type hash).

Use Cases

  • Filter events by type

From Chain Metadata

Mapping between a topic (represented by T::Hash) and a vector of indexes of events in the `<Events<T>>` list. All topic vectors have deterministic storage locations depending on the topic. This allows light-clients to leverage the changes trie storage tracking mechanism and in case of changes fetch the list of events of interest. The value has the type `(T::BlockNumber, EventIndex)` because if we used only just the `EventIndex` then in case if the topic has the same contents on the next block no notification will be triggered thus the event might be lost.

Purpose & Usage

Purpose

Enable efficient event filtering by topic.

Common Query Patterns

  • Query by topic hash

Query Keys

#NameTypeDescription
1
topic
raw: key1
H256 [u8; 32]key1 (H256)

Stored Value

value (Vec<(u32, u32)>)

Default Value

0x00 (raw SCALE bytes)

Absent keys read as this value — querying a key that has never been written returns this default, not an error or empty result.

Code Examples

import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443

const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);

// Query EventTopics storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";

const result = await api.query.System.EventTopics.getValue(key1);
console.log("EventTopics:", result);

Runtime Info

Pallet
System
Storage Kind
Map
First Version
v101
Current Version
v472