Skip to main content

System Models

EasyLayer includes built-in models that run automatically alongside your custom models. They handle chain integrity monitoring and mempool state out of the box. You can subscribe to their events and query their state without writing any model code.


Network Chain Model​

The Network Chain Model tracks the state of the blockchain as the crawler sees it. It runs on every crawler instance.

What it does:

  • Maintains the current chain tip: block height, hash, and timestamp
  • Detects and records blockchain reorganizations as they happen
  • Optionally validates block headers using Merkle proofs

Events it emits:

EventWhenPayload
BitcoinNetworkInitializedEventCrawler startschain info, start height
BitcoinNetworkBlocksAddedEventNew blocks confirmedblock heights, hashes
BitcoinNetworkReorganizedEventReorg detected and resolvedorphaned blocks, new blocks
EvmNetworkInitializedEventEVM crawler startschain ID, start block
EvmNetworkBlocksAddedEventNew EVM blocks confirmedblock numbers, hashes
EvmNetworkReorganizedEventEVM reorg detectedorphaned and new blocks

Subscribing:

client.subscribe('BitcoinNetworkBlocksAddedEvent', (event) => {
console.log('New blocks:', event.payload.blocks.map(b => b.height));
});

client.subscribe('BitcoinNetworkReorganizedEvent', (event) => {
console.log('Reorg! Orphaned:', event.payload.orphanedBlocks.length, 'blocks');
});

Querying chain state:

const stats = await client.query('GetNetworkStatsQuery');
console.log(stats.currentHeight, stats.syncProgress);

const latest = await client.query('GetNetworkLastBlockQuery');
console.log(latest.height, latest.hash);

Mempool Model​

The Mempool Model is available when mempool monitoring is enabled. It maintains a snapshot of current pending transactions.

What it does:

  • Polls the connected node for mempool contents on a configurable interval
  • Emits a refresh event on every poll
  • Tracks which mempool transactions get confirmed vs dropped

Events it emits:

EventWhenPayload
BitcoinNetworkMempoolRefreshedEventEach mempool polllist of pending transactions
EvmMempoolRefreshedEventEach EVM mempool polllist of pending transactions

Subscribing:

client.subscribe('BitcoinNetworkMempoolRefreshedEvent', (event) => {
const { transactions } = event.payload;
console.log(`${transactions.length} unconfirmed transactions in mempool`);
});

See Mempool Monitoring for configuration and custom model integration.


Merkle Validation (Bitcoin)​

Optionally enable Merkle proof validation to cryptographically verify that each block's transactions match its header commitment. Useful for high-integrity deployments where you want to catch any data integrity issues.

BITCOIN_MERKLE_VALIDATION=true

When enabled, the crawler verifies every block before processing it. Invalid blocks are rejected and the crawler reconnects to the provider.


Using System Events in Your App​

System events use the same transport as your custom model events. You subscribe with the same client.subscribe() call. No extra configuration needed.

Common patterns:

  • Listen to BlocksAdded to trigger downstream processing in your own service
  • Listen to Reorg events to invalidate caches or send alerts
  • Poll GetNetworkStatsQuery to display sync progress in a dashboard
  • Use GetNetworkLastBlockQuery to check crawler health in a monitoring endpoint