API Servers

Purpose

API Servers provide the crucial interface layer between client applications and the underlying blockchain data and services. This subtopic addresses the need for exposing blockchain information and transaction capabilities through standardized, developer-friendly RESTful and WebSocket APIs. These servers abstract away blockchain-specific complexities, allowing clients to query account data, transaction history, send transactions, estimate fees, and subscribe to real-time blockchain events.

While the parent topic covers the modular implementations of blockchain nodes and APIs, the API Servers subtopic focuses specifically on the server-side application logic that enables interaction with blockchain node daemons and indexers. It solves the challenge of unifying various blockchain data sources into a consistent API surface, ensuring scalability, real-time updates, and extensibility across different blockchains.

Functionality

API Servers implement the following key workflows and features:

Example Workflow: New Block Event Handling

  1. The server’s WebSocket client listens to the indexer’s block event stream.

  2. On receiving a new block, the blockHandler asynchronously fetches and processes transactions via service controllers.

  3. Transactions are parsed, enriched (e.g., internal txs for Ethereum), and relevant addresses are extracted.

  4. The registry updates subscriptions and dispatches notifications to WebSocket clients subscribed to those addresses.

This flow ensures clients receive timely updates about the blockchain state changes they care about.

const blockHandler: BlockHandler<NewBlock, Array<BlockbookTx>> = async (block) => {
  const txs = await service.handleBlock(block.hash)
  return { txs }
}

Integration

API Servers are tightly integrated within the broader blockchain node ecosystem:

The API Servers complement daemon node management and indexer services by acting as the gateway layer that ensures efficient, scalable, and user-friendly access to blockchain data and operations.

Diagram

sequenceDiagram
  participant Client as Client Application
  participant APIServer as API Server (Express.js / Go)
  participant Registry as Subscription Registry
  participant Blockbook as Blockchain Indexer (Blockbook)
  participant Daemon as Blockchain Daemon Node

  Client->>APIServer: REST Request (e.g., Tx History)
  APIServer->>Registry: Query cached data / services
  Registry->>Blockbook: Query blockchain data
  Blockbook-->>Registry: Return blockchain data
  Registry-->>APIServer: Formatted response data
  APIServer-->>Client: JSON response

  Client->>APIServer: WS Subscription (addresses)
  APIServer->>Registry: Register subscription

  Blockbook->>APIServer: New block / tx event (WS)
  APIServer->>Registry: Process block/tx
  Registry-->>Client: Push relevant event updates

  Client->>APIServer: POST Send Transaction
  APIServer->>Daemon: Broadcast raw transaction
  Daemon-->>APIServer: Tx broadcast result
  APIServer-->>Client: Tx hash / status

This sequence highlights how API Servers mediate between clients, blockchain data providers, and node daemons to deliver real-time and on-demand blockchain services.


This subtopic focuses on API Servers’ specialized role in delivering blockchain data and operations through robust REST and WebSocket endpoints, leveraging chain-specific logic to provide a unified and extensible interface for diverse blockchain ecosystems.