A high-performance Ethereum RPC client with zero-copy parsing for maximum efficiency.
- Zero Allocation JSON Parsing: Optimized for speed and efficiency.
- Connection Pooling: Reuse connections for faster requests.
- Concurrent Batch Requests: Handle multiple requests simultaneously.
- High Throughput: Processes 2300+ blocks/second.
The transport layer is responsible for executing RPC requests.
pub trait Transport: Send + Sync + std::fmt::Debug {
async fn execute_raw(&self, request: String) -> Result<Vec<u8>, RpcError>;
async fn execute(&self, request: String) -> Result<String, RpcError>;
async fn execute_with_retry(&self, request: String, retry: usize) -> Result<String, RpcError>;
async fn connect(&self) -> Result<(), RpcError>;
}
pub async fn get_chain_id(&self) -> Result<U64, RpcError>
// Get current gas price
pub async fn get_gas_price(&self) -> Result<U256, RpcError>
// Get current block number
pub async fn get_block_number(&self) -> Result<U64, RpcError>
pub async fn get_block_by_number(
&self,
number: u64,
full_tx: bool,
) -> Result<Option<Block>, RpcError>
// Get block header only
pub async fn get_block_header_by_number(
&self,
number: u64,
full_tx: bool
) -> Result<Option<BlockHeader>, RpcError>
pub async fn get_transaction_by_tx_hash(
&self,
hash: B256
) -> Result<Option<TransactionTx>, RpcError>
// Get transaction by block and index
pub async fn get_transaction_by_block_with_index(
&self,
block: BlockIdentifier,
index: U64
) -> Result<Option<TransactionTx>, RpcError>
pub async fn get_balance(
&self,
address: Address,
block: BlockNumber
) -> Result<U256, RpcError>
// Get contract code
pub async fn get_code(
&self,
address: Address,
block: BlockNumber
) -> Result<Bytes, RpcError>
pub async fn get_logs(
&self,
from_block: u64,
to_block: u64,
address: Option<Address>,
topics: Option<Vec<B256>>
) -> Result<Option<Vec<Log>>, RpcError>
- Zero Allocation Parsing: Faster and memory efficient.
- Benchmarks:
- MacBook Air M3:
- 1000 Concurrent Requests for blocks: 431ms.
- Log Fetching: ~95% faster than standard implementations.
- Block Processing: ~2300 blocks/second.
- Performance varies depending on hardware.
- MacBook Air M3:
let client = RpcClient::new(transport);
// Fetch blocks concurrently
let blocks = client.get_block_by_number(block_num, false).await?;
Contributions are welcome! Please submit issues or pull requests to help improve this library.
This project is licensed under MIT License.