A blockchain indexer for the Trixy Protocol on Flow Network. Indexes prediction market events including market creation, bet placement, resolution, winnings claims, and yield operations.
- 🔄 Real-time event indexing from Flow blockchain
- 📊 PostgreSQL storage with GORM
- 🔍 Continuous block monitoring with automatic sync state management
- 🎯 Event tracking:
- MarketCreated
- BetPlaced
- MarketResolved
- WinningsClaimed
- YieldDeposited
- YieldWithdrawn
- ✅ Code quality with golangci-lint
- 🚀 Batch processing for efficient indexing
- Go 1.21+
- PostgreSQL 13+
- Flow gRPC access node endpoint
-
Clone the repository:
git clone <repository-url> cd indexer
-
Install dependencies:
go mod download
-
Install golangci-lint (optional, for development):
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest export PATH=$PATH:$HOME/go/bin
-
Copy the example config:
cp config-example.yaml config.yaml
-
Edit
config.yaml:mode: "indexer" dbType: "postgres" dbHost: "localhost" dbPort: 5432 dbUser: "your_username" dbPass: "your_password" # Leave empty for passwordless auth dbName: "trixy-flow-indexer" rpcEndpoint: "access.devnet.nodes.onflow.org:9000" network: "flow-testnet" networksFile: "networks.json" indexWorkers: 2 forceResyncOnEveryStart: false migrateOnStart: true blockBatchSize: 50
-
Configure networks in
networks.json:{ "flow-testnet": { "TrixyProtocol": { "address": "0xe4a8713903104ee5", "startBlock": 287066000 } } }
Create the PostgreSQL database:
psql -U postgres
CREATE DATABASE "trixy-flow-indexer";Tables are auto-created on first run when migrateOnStart: true.
go run main.gogo build -o trixy-indexer
./trixy-indexergolangci-lint run --fix.
├── main.go # Entry point and main indexing loop
├── config/
│ ├── config.go # Configuration management
│ ├── db.go # Database connection
│ └── flow_models.go # Flow event data models
├── indexer/
│ ├── indexer.go # Indexing logic (for EVM contracts)
│ ├── parser.go # Event parsing
│ └── rpc.go # RPC client
├── .golangci.yml # Linter configuration
├── config.yaml # Runtime config (gitignored)
├── config-example.yaml # Config template
└── networks.json # Network contract addresses
- Initialization: Load config, connect to database, create Flow gRPC client
- Sync State: Check last indexed block from database
- Block Processing: Query events in batches (default: 200 blocks)
- Event Parsing: Parse Cadence event data into Go structs
- Storage: Store events in PostgreSQL with deduplication
- State Update: Update sync state after each successful batch
- Continuous Loop: Poll for new blocks every 2 seconds
flow_market_createds- Market creation eventsflow_bet_placeds- Bet placement eventsflow_market_resolveds- Market resolution eventsflow_winnings_claimeds- Winnings claim eventsflow_yield_depositeds- Yield deposit eventsflow_yield_withdrawns- Yield withdrawal eventsflow_sync_states- Indexer sync state per contract
The project uses golangci-lint with auto-fixable linters:
gofmt,gofumpt- Code formattinggoimports,gci- Import managementwhitespace- Whitespace consistencygosimple,staticcheck- Code qualityerrcheck- Error handling checksrevive,stylecheck- Style consistency
access.devnet.nodes.onflow.org:9000
access.mainnet.nodes.onflow.org:9000
Add Go bin to PATH:
export PATH=$PATH:$HOME/go/binEnsure PostgreSQL is running and credentials are correct:
psql -U your_username -d trixy-flow-indexerVerify the gRPC endpoint is accessible:
grpcurl access.devnet.nodes.onflow.org:9000 listMIT