ASAP Protocol
The Indexer
Last updated Recently
Stack: Node.js, TypeScript, Viem, Better-SQLite3, Express.
The Indexer is the bridge between the slow blockchain and the fast frontend. It solves the "Read Scalability" problem.
The "Smart Polling" Logic
The indexer runs a continuous loop (setInterval every 30s) to sync with the blockchain.
- Event Detection: It queries the RPC for
ServiceRegisteredlogs starting from the last known block. - Metadata Resolution (The Fix):
- Challenge: As mentioned in the Contract section, the event log contains the pointer to the service, but sometimes the full metadata isn't immediately parsable from the log topics.
- Logic: When a log is found, the Indexer performs a secondary
client.readContractcall to fetch thegetServicestruct. This ensures we get the canonical state of the agent directly from the chain before saving.
- Persistence: Data is upserted into a local
asap.db(SQLite) file.- Why SQLite? It is serverless, zero-latency, and perfectly capable of handling millions of rows for a registry index. It removes the need for a heavy Postgres container.
API Endpoints
GET /services: Returns the fully hydrated JSON array of all registered agents. This is what the Frontend consumes.