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:
-
HTTP Server (
http_addr): Public JSON-RPC endpoint for standard Ethereum methods (eth_*,debug_*,net_*,admin_*,web3_*,txpool_*). -
WebSocket Server (
ws): Optional endpoint that serves the same methods as HTTP plus the subscription methodseth_subscribe/eth_unsubscribe(currently only"newHeads"is supported). Enabled by passing aWebSocketConfigcontaining the listen address and theSubscriptionManageractor handle. -
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- OptionalWebSocketConfigwith the WS listen address and theSubscriptionManageractor handle.Nonedisables the WebSocket server.authrpc_addr- Socket address for authenticated Engine API (e.g.,127.0.0.1:8551)storage- Database storage instanceblockchain- Blockchain instance for block operationsjwt_secret- JWT secret for Engine API authenticationlocal_p2p_node- Local node identity for P2P networkinglocal_node_record- ENR for node discoverysyncer- Sync manager for block synchronizationpeer_handler- Handler for P2P peer operationsclient_version- Client version information forweb3_clientVersionandengine_getClientVersionV1log_filter_handler- Optional handler for dynamic log level changesgas_ceil- Maximum gas limit for payload buildingextra_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).