Skip to main content

Crate ethrex_rpc

Crate ethrex_rpc 

Source
Expand description

§ethrex RPC

This crate implements the Ethereum JSON-RPC API for the ethrex node.

§Overview

The RPC server provides three interfaces:

  • HTTP API: Public JSON-RPC endpoint for client requests (eth_*, debug_*, net_*, etc.)
  • WebSocket API: Optional WebSocket endpoint for subscriptions and real-time updates
  • Auth RPC API: Authenticated endpoint for consensus client communication (engine_* methods)

§Supported Namespaces

  • eth: Standard Ethereum methods (blocks, transactions, accounts, gas estimation)
  • engine: Consensus layer methods for block building and fork choice
  • debug: Debugging methods (raw blocks, execution witnesses, tracing)
  • net: Network information methods
  • admin: Node administration methods
  • web3: Web3 utility methods
  • txpool: Transaction pool inspection methods

§Usage

use ethrex_rpc::{start_api, RpcApiContext};

// Start the RPC server
start_api(
    http_addr,
    ws_addr,
    authrpc_addr,
    storage,
    blockchain,
    jwt_secret,
    // ... other parameters
).await?;

§Implementing Custom RPC Handlers

Implement the RpcHandler trait to create custom RPC endpoints:

use ethrex_rpc::{RpcHandler, RpcApiContext, RpcErr};

struct MyHandler { /* fields */ }

impl RpcHandler for MyHandler {
    fn parse(params: &Option<Vec<Value>>) -> Result<Self, RpcErr> {
        // Parse JSON-RPC parameters
    }

    async fn handle(&self, context: RpcApiContext) -> Result<Value, RpcErr> {
        // Handle the request
    }
}

Re-exports§

pub use clients::EngineClient;
pub use clients::EthClient;
pub use rpc::start_api;
pub use rpc::start_block_executor;
pub use rpc::ClientVersion;
pub use rpc::NodeData;
pub use rpc::RpcApiContext;
pub use rpc::RpcHandler;
pub use rpc::RpcRequestWrapper;
pub use rpc::WebSocketConfig;
pub use rpc::handle_eth_subscribe;
pub use rpc::handle_eth_unsubscribe;
pub use rpc::handle_websocket;
pub use rpc::map_debug_requests;
pub use rpc::map_eth_requests;
pub use rpc::map_http_requests;
pub use rpc::rpc_response;
pub use rpc::shutdown_signal;
pub use subscription_manager::SubscriptionManager;
pub use subscription_manager::SubscriptionManagerProtocol;
pub use utils::RpcErr;
pub use utils::RpcErrorMetadata;
pub use utils::RpcNamespace;

Modules§

clients
debug
engine
rpc
subscription_manager
Actor-based subscription manager for WebSocket eth_subscribe connections.
types
utils
Utility types and error handling for JSON-RPC.

Structs§

EstimateGasRequest
GasPrice
Handler for the eth_gasPrice RPC method.
GasTipEstimator
Struct in charge of performing gas tip estimations & saving latest results for following estimations

Constants§

DEFAULT_HTTP_API
Default namespaces enabled on the public HTTP/WS RPC endpoint.

Functions§

clean_outdated_filters
Used by the tokio runtime to clean outdated filters Takes 2 arguments:

Type Aliases§

ActiveFilters
Maps IDs to active pollable filters and their timestamps.