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 choicedebug: Debugging methods (raw blocks, execution witnesses, tracing)net: Network information methodsadmin: Node administration methodsweb3: Web3 utility methodstxpool: 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_subscribeconnections. - types
- utils
- Utility types and error handling for JSON-RPC.
Structs§
- Estimate
GasRequest - GasPrice
- Handler for the
eth_gasPriceRPC method. - GasTip
Estimator - 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§
- Active
Filters - Maps IDs to active pollable filters and their timestamps.