Wildcard indexing is one of Envio's latest features, designed to simplify how you index events. With this feature, you can capture all events matching a specified signature, without needing to specify the contract address from which the event was emitted. Here's how it works.
What Is Wildcard Indexing?
[Wildcard indexing])https://docs.envio.dev/docs/HyperIndex/wildcard-indexing) is especially useful when you're dealing with contracts deployed via factories, where the factory contract doesn't emit events on contract creation. It's also perfect for indexing events from all contracts that implement common standards, like ERC20.
For example, if you want to index all Transfer events, you can use a configuration like this:
How to Index All Events with Wildcard Indexing
Once you've set up your configuration, you can write your event handler in TypeScript, JavaScript, or ReScript. The result? All Transfer events will be indexed, no matter which contract emitted them.
Here’s an example of the event handler code:
Filtering Specific Events
Let’s say you only want to index Mint and Transfer events where the from
address is equal to 0x0000000000000000000000000000000000000000
. No problem! Just add a filter to your event handler like this:
If you need to track multiple filters, such as mint/burn events for a set of whitelisted addresses, you can do so with ease:
Advanced Use with APIs
Wildcard indexing also extends to contractRegister and handlerWithLoader APIs. For example, you can register only Uniswap pools containing the DAI token by using a filter like this:
For handlerWithLoader, simply add the wildcard
or eventFilters
to the loader function:
Limitations to Keep in Mind
- One event per signature: For any given network, only one event of a given signature can be indexed using wildcard indexing.
-
Config usage: Either the
contractRegister
or thehandler
function can take an event config object (withwildcard
/eventFilters
fields), but not both. - No RPC sync: RPC sync is not yet supported for wildcard indexing.
Why Use Wildcard Indexing?
Wildcard indexing opens up new possibilities for flexibility and efficiency when handling on-chain events. By leveraging these features, you can create indexing solutions that are more powerful, scalable, and tailored to your specific use cases. ⚡️
For more details, check out our full documentation on Wildcard Indexing.
About Envio
Envio is a modern, dev-friendly, speed-optimized blockchain indexing solution that addresses the limitations of traditional blockchain indexing approaches and gives developers peace of mind. Blockchain developers and data analysts can harness the power of Envio to overcome the challenges posed by latency, reliability, infrastructure management, and costs across various sources.
If you're a blockchain developer looking to enhance your development process and unlock the true potential of Web3 infrastructure, look no further.
Join our growing community of Web3 developers, check out our docs, and let's work together to revolutionize the blockchain world and propel your project to the next level.
Top comments (0)