Wildcard Transfer Example
This example demonstrates different approaches to indexing ERC20 transfer events, showcasing both auto-generated and custom entity handling.
The indexer will:
- Automatically store all Transfer events in the generated entity table
- Log when it sees DAI or USDT transfers
- Create a new example entity for each transfer event
Key Components
1. Auto-Generated Entity Handling (/output folder)
- Contains entities automatically generated by the
solidity-events-to-typeormpackage - The
TransferEntity_fab013d9is auto-generated from the Transfer event ABI - These entities are automatically populated - no custom listener required!
- Extends
BlockchainEventEntitywhich provides common blockchain event fields
2. Custom Entity Handling (/custom folder)
- Contains manually created entities for custom data storage
- Demonstrates how to store additional/transformed data alongside auto-generated entities
- In this example,
ExampleEntityis used to demonstrate custom storage
3. Event Listeners
The example implements two different listeners:
- Simple Console Logger (
subscriptions.ts):
onEvent('*:Transfer', {
onIndex: async (payload) => {
// Filters and logs USDT and DAI transfers
},
});- Custom Entity Storage (
transfer-subscriber.ts):
@Injectable()
export class TransferSubscriber extends AbstractEventSubscriber {
readonly eventPattern = '*:Transfer';
async onIndex(payload: LogEvent, context: LogContext): Promise<void> {
// Creates and stores a new ExampleEntity for each transfer
}
}4. Configuration
The indexer is configured in indexerConfig to:
- Listen to Transfer events from any contract
- Start from block 22229952
- Track transfers from specific contracts (DAI and USDT)
- Enable both auto-generated and custom entity storage
How It Works
-
Auto-Generated Indexing:
- Transfer events are automatically indexed into
transfer_fab013d9table - No custom code needed for basic transfer data storage
- Handles all common event fields (block number, transaction hash, etc.)
- Transfer events are automatically indexed into
-
Custom Processing:
- The
subscriptions.tslistener filters and logs DAI/USDT transfers - The
TransferSubscriberdemonstrates custom entity creation - Each transfer triggers storage of a new example entity with random data
- The
Example Transactions
You can view example transfers that this indexer should print "DAI" or "USDT" for here:
Setup and Usage
-
Set up environment variables - copy
.env.exampleto.envand replace with your variables -
Install dependencies:
pnpm install- Run the indexer:
pnpm startProject Structure
src/
├── output/ # Auto-generated entities and migrations
│ └── entities/ # Contains TransferEntity_fab013d9
├── custom/ # Custom entities and migrations
│ └── entities/ # Contains ExampleEntity
├── subscriptions.ts # Basic transfer event listener
├── transfer-subscriber.ts # Custom entity storage listener
└── indexer.config.ts # Indexer configurationThis example demonstrates the flexibility of the indexer, showing both automatic event indexing and custom data processing approaches.