eth_rpc

Crates.ioeth_rpc
lib.rseth_rpc
version0.2.6
sourcesrc
created_at2023-08-07 07:58:45.309708
updated_at2023-11-13 19:49:30.919767
descriptionsimple eth rpc with helper functions
homepagehttps://github.com/copiumnicus/eth_rpc
repositoryhttps://github.com/copiumnicus/eth_rpc
max_upload_size
id937752
size59,086
copiumnicus (copiumnicus)

documentation

README

eth_rpc

Test

Features

eth_rpc is a simple, portable eth rpc (partial) implementation with features like:

  • Helper methods: token symbol, token decimals, ethers-rs abigen compatible eth_call, get function for revm AccountInfo model
  • transports like: Ipc, Http, EnvHttp, RandomizeHttp (for that sweet multiple node provider links setup under the hood)
  • Config serialization support
  • Most common tx submission errors
  • json rpc batch
  • Sync (take back control over your thread runtime and run it on linux threads not on tokio)
  • Rate limit (for alchemy for instance) and network error protection

(Incomplete) Features Overview

All calls under the hood (EXCEPT TX SUBMISSION FOR FULL CONTROL) use no ratelimit rpc

pub fn no_ratelimit_rpc<R>(&self, jr: JRCall) -> Result<R, JRError>
where
    R: for<'a> Deserialize<'a>,

The abigen compatible eth call:

/// simple wrapper on top of eth call to work with abigen! macro
pub fn eth_call_typed<R>(&self, to: H160, calldata: impl AbiEncode) -> Result<R, JRError>
where
    R: AbiDecode,

The json rpc (chunked) batching compatibility:

/// in case of error returns first JRError encountered
pub fn batch(&self, requests: Vec<JRCall>) -> Result<Vec<SafeJRResult>, JRError>

Erc20 helpers:

pub fn get_balance(&self, token: H160, account: H160) -> Result<U256, JRError>;
pub fn get_decimals(&self, token: H160) -> Result<u8, JRError>;
pub fn get_symbol(&self, token: H160) -> Result<String, JRError>;
/// for MKR token
pub fn get_bytes32_symbol(&self, token: H160) -> Result<String, JRError>;

Custom tx submit error (will handle more based on downstream demand)

#[derive(Debug)]
pub enum SubmitTxError {
    JRErr(JRError),
    NonceTooLow,
    ReplacementUnderpriced,
    BaseGasPriceTooLow(String),
}

Example rpc serialized (json) config (uses all https randomly under the hood):

{
  "batch_chunk_size": 5,
  "transport": {
    "RandomizeHttps": [
      "https://omniscient-few-darkness.quiknode.pro/fake0/",
      "https://eth-mainnet.g.alchemy.com/v2/fake1",
      "https://eth-mainnet.g.alchemy.com/v2/fake2",
      "https://eth-mainnet.g.alchemy.com/v2/fake3"
    ]
  }
}

Functions for:

  • eth_blockNumber
  • eth_estimateGas
  • eth_gasPrice
  • eth_getBlockByNumber (using ethers Block type)
  • eth_getLogs (using custom log type)
  • eth_getStorageAt
  • eth_getTransactionByHash
  • eth_getTransactionCount
  • eth_getTransactionReceipt (using ethers TransactionReceipt)

Testing

Populate the source_env.sh based on source_env_example.sh and run the tests with sh ./regression.sh

Commit count: 33

cargo fmt