17 releases
0.2.6 | Nov 13, 2023 |
---|---|
0.2.5 | Nov 13, 2023 |
0.2.2 | Sep 26, 2023 |
0.1.9 | Sep 8, 2023 |
0.1.7 | Aug 27, 2023 |
#2987 in Magic Beans
42 downloads per month
58KB
1.5K
SLoC
eth_rpc
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
Dependencies
~35–52MB
~1M SLoC