evmDecoder
Create a transformer that decodes smart contract events.
evmDecoder<T>(config: EvmDecoderConfig<T>): Transformer
Returns: A Transformer that transforms EvmPortalData into decoded events.
Parameters:
range: Block range { from: number | 'latest', to?: number } (required)
contracts: Array of contract addresses or factory (required)
events: Map of event names to ABI objects (required)
profiler: Profiler config { id: string } (optional)
Example:
import { evmDecoder, commonAbis } from "@subsquid/pipes/evm";
const transformer = evmDecoder({
range: { from: 20000000, to: 20100000 },
contracts: ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
events: {
transfer: commonAbis.erc20.events.Transfer,
},
});
Use @subsquid/evm-typegen to generate typed ABIs for custom contracts. This provides type safety and eliminates the need to manually find event signatures. See the Event Decoding guide for details on generating and using custom ABIs.
evmDecoder returns a Transformer that automatically builds the necessary queries for event decoding. You don’t need a query builder when using this transformer - it handles query construction internally. However, you still need a portal source.
Transform data in pipes.
createTransformer<I, O>(config: TransformerConfig<I, O>): Transformer<I, O>
Parameters:
transform: Transform function async (data: I, ctx) => O (required)
query: Query callback ({queryBuilder, portal, logger}) => void (optional)
Example:
const transformer = createTransformer({
query: ({ queryBuilder }) => {
queryBuilder.addLog({
request: { address: ["0x..."] },
range: { from: 20000000 },
});
},
transform: async (data) => {
return data.blocks.map((b) => b.logs);
},
});
Types
DecodedEvent
Structure of decoded smart contract events.
interface DecodedEvent<T, F = unknown> {
event: T;
contract: string;
block: {
number: number;
hash: string;
};
timestamp: Date;
rawEvent: {
address: string;
data: string;
topics: string[];
transactionHash: string;
logIndex: number;
transactionIndex: number;
};
factory?: {
contract: string;
blockNumber: number;
event: F;
};
}
EvmPortalData
Structure of raw blockchain data from the Portal API.
interface EvmPortalData<Q> {
blocks: Array<{
header: {
number: number;
hash: string;
timestamp: number;
// ... other fields
};
logs: Array<{
address: string;
topics: string[];
data: string;
transactionHash: string;
logIndex: number;
}>;
transactions: Array<{
hash: string;
from: string;
to: string;
value: bigint;
// ... other fields
}>;
}>;
}
Next Steps