crates/storage/rpc-provider/README.md
This crate provides an RPC-based implementation of reth's BlockchainProvider which provides access to local blockchain data, this crate offers the same functionality but for remote blockchain access via RPC.
Originally created by cakevm.
BlockchainProvider but for remote nodesStateProviderFactory for remote RPC state accessuse alloy_provider::ProviderBuilder;
use reth_storage_rpc_provider::RpcBlockchainProvider;
// Initialize provider
let provider = ProviderBuilder::new()
.builtin("https://eth.merkle.io")
.await
.unwrap();
// Create RPC blockchain provider with NodeTypes
let rpc_provider = RpcBlockchainProvider::new(provider);
// Get state at specific block - same interface as BlockchainProvider
let state = rpc_provider.state_by_block_id(BlockId::number(16148323)).unwrap();
The provider can be configured with custom settings:
use reth_storage_rpc_provider::{RpcBlockchainProvider, RpcBlockchainProviderConfig};
let config = RpcBlockchainProviderConfig {
compute_state_root: true, // Enable state root computation
reth_rpc_support: true, // Use Reth-specific RPC methods (default: true)
};
let rpc_provider = RpcBlockchainProvider::new_with_config(provider, config);
compute_state_root: When enabled, computes state root and trie updates (requires Reth-specific RPC methods)
reth_rpc_support: When enabled (default), uses Reth-specific RPC methods for better performance:
eth_getAccountInfo: Fetches account balance, nonce, and code in a single calldebug_codeByHash: Retrieves bytecode by hash without needing the addressWhen disabled, falls back to standard RPC methods and caches bytecode locally for compatibility with non-Reth nodes.
The RpcBlockchainProvider uses alloy_network::AnyNetwork for network operations, providing compatibility with various Ethereum-based networks while maintaining the expected block structure with headers.
This provider implements the same traits as the local BlockchainProvider, making it a drop-in replacement for scenarios where remote RPC access is preferred over local database access.
Licensed under either of:
at your option.