Worker API
An event-driven indexer and API layer for Lightchain AI worker activity. It watches on-chain events, stores derived entities in PostgreSQL, and serves the indexed data through Express and GraphQL.Architecture Overview
At runtime, the service works like this:CodeTEXT
- loads environment variables and the GraphQL schema.CodeHTML
- A instance is created withCodeHTML.CodeHTML
- The EVM indexers are registered.
- Checkpoint starts polling configured contracts.
- Express serves REST routes under and GraphQL atCodeHTML.CodeHTML
What The Service Indexes
The current indexer watches three contracts:- CodeHTML
- CodeHTML
- CodeHTML
Contract addresses and start blocks are still hardcoded in src/evm/config.ts.
The repo ships with placeholder values and must be updated before real indexing will work.
Prerequisites
Before starting the service, make sure you have:- Bun CodeHTML
- PostgreSQL
- an RPC endpoint for the intended Lightchain AI-compatible chain
CodeHTML
Local Setup
1. Install dependencies
CodeBASH
2. Create your environment file
CodeBASH
CodeENV
3. Update contract config
Before indexing real chain data, replace the placeholders inCodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
4. Generate Checkpoint models
CodeBASH
CodeHTML
CodeHTML
5. Start the service
Development mode:CodeBASH
CodeBASH
Package Scripts
Indexed Event Coverage
CodeHTML
CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
CodeHTML
CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
CodeHTML
CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
Data Model
The GraphQL schema lives inCodeHTML
- is the worker addressCodeHTML
- isCodeHTMLCodeHTML
- is the stringified on-chainCodeHTMLCodeHTML
- is the stringified on-chainCodeHTMLCodeHTML
- is alwaysCodeHTMLCodeHTML
- isCodeHTMLCodeHTML
REST API
CodeHTML
Returns:
CodeHTML
CodeJSON
CodeHTML
Returns:
CodeHTML
CodeJSON
- the request body is unused
- the route does not write to the database
- it simply calls and returns the resultCodeHTML
GraphQL Usage
Checkpoint mounts GraphQL atCodeHTML
CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
- CodeHTML
Derived Behavior To Know About
Some values in the API are derived rather than directly stored on-chain.Worker status
The code derives worker status from:- CodeHTML
- CodeHTML
- CodeHTML
Slash correlation
The writer layer keeps an in-memory correlation map so aCodeHTML
- CodeHTML
- CodeHTML
CodeHTML
Global counters
CodeHTML
Known Caveats
These are current implementation realities:-
Online detection is stubbed.
currently returnsCodeHTMLfor every worker.CodeHTML
-
Contract config is not environment-driven.
Addresses and start blocks are hardcoded in .CodeHTML
-
removals are not persisted as removals.CodeHTMLupdates the worker timestamp, but does not delete or deactivate theCodeHTMLrecord.CodeHTML
-
Some fields are placeholders.CodeHTMLandCodeHTMLare initialized, but are not populated from indexed events in the current implementation.CodeHTML
-
is only partially modeled. Sessions are created asCodeHTMLand are not fully transitioned through every on-chain state.CodeHTML
- Slash correlation is in-memory. A process restart can break same-block correlation between related events.
- There is no committed test suite yet. Changes should be validated manually or covered with new tests.
The API is useful today, but it should be treated as an evolving indexer rather than a finalized production data contract.
Common Maintenance Tasks
Add a new indexed event
- Update the ABI under if needed.CodeHTML
- Add the event mapping in .CodeHTML
- Implement the writer in .CodeHTML
- If the schema changes, update and rerunCodeHTML.CodeHTML
Replace the online check
Implement the real availability logic inCodeHTML
CodeTYPESCRIPT
Move contract config to environment variables
If you want deployable environments without source edits:- Read contract addresses and start blocks from .CodeHTML
- Extend .CodeHTML
- Validate those values near the top of .CodeHTML
Troubleshooting
CodeHTML
is missing
Run:
CodeHTML
CodeBASH
The service starts but no data appears
Check these first:- points to the intended chainCodeHTML
- the contract addresses are real
- the configured start blocks are correct
- PostgreSQL is reachable through CodeHTML
REST works but GraphQL is empty
That usually means Express is healthy but the indexer is not ingesting events. In this repository, the most common causes are:- placeholder contract config
- RPC issues
- database connectivity issues
Related Guides
Last updated: March 2026