Transformers allow you to process and reshape data as it flows through your pipeline. This guide demonstrates creating custom transformers for common use cases.
Create a basic transformer
Adding Transformer
Extract transaction hashes from logs.Use case: Transform raw Portal data before logging.Your transformer extracts transaction hashes from all logs in the batch, making them easy to log or further process.
Create a query-aware transformer
Query from Transformer
Build query dynamically in transformer.Use case: Self-contained transformers that specify their own data requirements.Key Distinction: Transformers can operate in two ways:
- Pure transformation (first example): Only implements
transform()— processes data after the Portal query is executed. - Query-aware transformation (this example): Implements both
query()andtransform()— contributes to building the Portal query and processes the resulting data.
query() method, it augments the Portal query before data is fetched, allowing transformers to be self-contained with their data requirements.Your query-aware transformer is now self-contained, specifying both what data it needs and how to process it.
Next Steps
- Factory Transformers - Learn about the advanced factory pattern for dynamically tracking contracts
- Component Reference: Transformer - Explore the full Transformer API
- Best Practices - Follow recommended patterns for transformers

