0Pricing
Web3 & DApp Development Fundamentals · レッスン

インデックス付きパラメーター

フィルタリング可能なトピック

「インデックス付きパラメーター」はCoddyKit上の無料Web3 & DApp Development Fundamentalsレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb3 & DApp Development Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Filtering Logs

Once a contract emits many events, off-chain apps need a way to filter them efficiently, for example to find every Transfer to a specific address.

Solidity supports this with indexed event parameters, which become searchable topics.

The indexed Keyword

Mark a parameter indexed to store it as a log topic rather than in the data section. Topics can be filtered quickly by Ethereum nodes.

<code>event Transfer(
    address indexed from,
    address indexed to,
    uint256 amount
);</code>

Topics vs Data

Each log has up to 4 topics and an arbitrary data blob:

  • Topic 0 is the event signature hash (automatic for non-anonymous events)
  • Each indexed parameter takes one more topic slot
  • Non-indexed parameters go into the data section

The Three-Indexed Limit

A non-anonymous event can have at most three indexed parameters, because topic 0 is reserved for the signature hash.

Adding a fourth indexed parameter is a compile error.

<code>// OK: 3 indexed params
event Trade(
    address indexed maker,
    address indexed taker,
    uint256 indexed orderId,
    uint256 price // not indexed
);</code>

Choosing What to Index

Index the fields you will search by: addresses, ids, categories. Keep large or descriptive values (amounts, strings) non-indexed so they stay readable in the data section.

<code>event ItemSold(
    uint256 indexed itemId,
    address indexed buyer,
    uint256 price
);</code>

Indexing Strings and Bytes

When you index a dynamic type like string or bytes, the topic stores the keccak256 hash of the value, not the value itself.

You can still filter by hashing the search term, but you cannot recover the original text from the topic.

<code>event Tagged(string indexed label, uint256 value);
// topic = keccak256(label), original text not in log</code>

Filtering on the Client

Client libraries use indexed topics to build filters. For example, fetching all transfers received by one address becomes a fast topic match.

<code>// ethers.js (off-chain)
// const filter = token.filters.Transfer(null, myAddress);
// const logs = await token.queryFilter(filter);</code>

The Standard Transfer Event

ERC-20 and ERC-721 define a Transfer event with indexed addresses. This is why wallets can show your incoming and outgoing transfers so quickly.

<code>// ERC-20
event Transfer(address indexed from, address indexed to, uint256 value);
// ERC-721
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);</code>

Gas Considerations

Indexed parameters cost slightly more gas than non-indexed ones because they occupy dedicated topic slots. Index only what you genuinely need to filter on.

Anonymous Events

An anonymous event omits the signature hash from topic 0, freeing a fourth indexed slot. They are rare and harder to decode, so use them only for advanced low-level cases.

<code>event LowLevel(uint256 indexed a, uint256 indexed b,
               uint256 indexed c, uint256 indexed d) anonymous;</code>

Mixing Indexed and Data

A practical event indexes the searchable keys and leaves descriptive payload in data, balancing filterability and readability.

<code>event Deposit(
    address indexed account, // searchable
    uint256 amount,          // readable in data
    uint256 timestamp
);</code>

Quick Check

Test your understanding of indexed parameters.

Recap

You learned about indexed event parameters:

  • indexed turns a parameter into a filterable topic
  • Max 3 indexed params (topic 0 = signature hash)
  • Indexed dynamic types store a keccak256 hash, not the value
  • Index searchable keys; keep descriptive payload in the data section

Good indexing makes off-chain queries fast and cheap.

よくある質問

「インデックス付きパラメーター」レッスンは無料ですか?

はい。「インデックス付きパラメーター」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web3 & DApp Development Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

「インデックス付きパラメーター」で何を学びますか?

フィルタリング可能なトピック ブラウザで直接実行するハンズオンコードでWeb3 & DApp Development Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web3 & DApp Development Fundamentalsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb3 & DApp Development Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「インデックス付きパラメーター」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb3 & DApp Development Fundamentalsレッスンでコードを書いて実行できますか?

はい。すべてのWeb3 & DApp Development Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. イベントの宣言
  2. インデックス付きパラメーター
  3. イベントの監視
  4. イベントとストレージの違い
← Web3 & DApp Development Fundamentalsに戻る