Transformers allow you to process and reshape data as it flows through your pipeline. This guide demonstrates creating custom transformers for common use cases.
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() and transform() — contributes to building the Portal query and processes the resulting data.
When a transformer has a 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.
Best Practices - Follow recommended patterns for transformers
For better type safety and developer experience, use solanaInstructionDecoder with ABIs generated by @subsquid/solana-typegen. See the Instruction Decoding guide for a typed approach.