Skip to main content

start_api

Function start_api 

Source
pub async fn start_api(
    http_addr: SocketAddr,
    ws: Option<WebSocketConfig>,
    authrpc_addr: SocketAddr,
    storage: Store,
    blockchain: Arc<Blockchain>,
    jwt_secret: Bytes,
    local_p2p_node: Node,
    local_node_record: NodeRecord,
    syncer: SyncManager,
    peer_handler: PeerHandler,
    client_version: ClientVersion,
    log_filter_handler: Option<Handle<EnvFilter, Registry>>,
    gas_ceil: u64,
    extra_data: String,
    allowed_namespaces: HashSet<RpcNamespace>,
) -> Result<(), RpcErr>
Expand description

Starts the JSON-RPC API servers.

This function initializes and runs up to three server endpoints:

  1. HTTP Server (http_addr): Public JSON-RPC endpoint for standard Ethereum methods (eth_*, debug_*, net_*, admin_*, web3_*, txpool_*).

  2. WebSocket Server (ws): Optional endpoint that serves the same methods as HTTP plus the subscription methods eth_subscribe / eth_unsubscribe (currently only "newHeads" is supported). Enabled by passing a WebSocketConfig containing the listen address and the SubscriptionManager actor handle.

  3. Auth RPC Server (authrpc_addr): JWT-authenticated endpoint for Engine API methods (engine_*) used by consensus clients.

§Arguments

  • http_addr - Socket address for the HTTP server (e.g., 127.0.0.1:8545)
  • ws - Optional WebSocketConfig with the WS listen address and the SubscriptionManager actor handle. None disables the WebSocket server.
  • authrpc_addr - Socket address for authenticated Engine API (e.g., 127.0.0.1:8551)
  • storage - Database storage instance
  • blockchain - Blockchain instance for block operations
  • jwt_secret - JWT secret for Engine API authentication
  • local_p2p_node - Local node identity for P2P networking
  • local_node_record - ENR for node discovery
  • syncer - Sync manager for block synchronization
  • peer_handler - Handler for P2P peer operations
  • client_version - Client version information for web3_clientVersion and engine_getClientVersionV1
  • log_filter_handler - Optional handler for dynamic log level changes
  • gas_ceil - Maximum gas limit for payload building
  • extra_data - Extra data to include in mined blocks

§Errors

Returns an error if any server fails to bind to its address.

§Shutdown

All servers shut down gracefully on SIGINT (Ctrl+C).