onchain-patterns

Design event-driven indexing and Web3 state management resilient to chain reorganizations.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/prapanch/agent-coda --skill onchain-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: onchain-patterns
Source: https://github.com/prapanch/agent-coda/tree/main/web3/onchain-patterns
Command: npx skills add https://github.com/prapanch/agent-coda --skill onchain-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you avoid inconsistent or broken Web3 indexing and dApp state by teaching reliable on-chain data architecture that survives immutability and chain reorganizations.

Core Features & Use Cases

  • Events-first indexing: treat emitted events as the canonical source of truth for deriving state and building reliable indexers.
  • Reorg-aware design: implement confirmation thresholds, track block hashes, and design idempotent handlers to prevent corrupted off-chain data.
  • Subgraph/indexer architecture: choose between The Graph, custom indexers, direct RPC reads, or third-party APIs with clear trade-offs and operational constraints.
  • On-chain/off-chain bridging discipline: store CIDs on-chain correctly, pin content, and use secure off-chain signature patterns (e.g., EIP-712 with domain, nonce, expiry, and explicit action types).
  • Composability and contract integration readiness: design contract interfaces and behaviors that work cleanly with other contracts and external callers.

Quick Start

Use the onchain-patterns skill to plan an event-driven indexer that derives state from logs while implementing a confirmation window and reorg rollback handling for your target chain.

Frequently Asked Questions about onchain-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle chain reorgs when indexing blockchain events?

To handle chain reorgs during blockchain event indexing, implement confirmation thresholds, track block hashes, and design idempotent event handlers to safely rollback corrupted off-chain state. This ensures your indexer remains correct even if the canonical chain switches.

What is the best way to design event-driven indexing for Web3 state?

The best way to design event-driven indexing for Web3 state is to treat emitted smart contract events as the canonical source of truth. You can then derive state from logs while strictly separating raw logs from derived views to build reliable indexers.

How do I securely bridge off-chain data using EIP-712 signatures?

To securely bridge off-chain data using EIP-712 signatures, implement signature patterns that include a structured domain, nonce, expiry, and explicit action types. This validates the integrity and origin of off-chain messages intended for on-chain execution.

Should I use The Graph or a custom indexer for subgraph design?

Choosing between The Graph, a custom indexer, direct RPC reads, or third-party APIs depends on your specific operational constraints and trade-offs. You must evaluate query latency, indexing speed, and reorg handling requirements to make the optimal subgraph design choice.

Why does my off-chain database mismatch the on-chain state?

Your off-chain database mismatches the on-chain state because of missing confirmation windows and non-idempotent event handlers. Chain reorganizations can silently invalidate derived state if your indexer does not track block hashes and apply reorg rollback handling.