EthereumRpcClient

open class EthereumRpcClient(rpcUrl: String, networkId: String? = null, httpClient: HttpClient? = null)

Simple Ethereum JSON-RPC client for EVM-compatible chains.

Supports Ethereum, Base, and other EVM chains via configurable RPC URL.

Constructors

Link copied to clipboard
constructor(rpcUrl: String, networkId: String? = null, httpClient: HttpClient? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend fun call(to: String, data: String, from: String? = null, block: String = "latest"): String

Execute a read-only contract call.

Link copied to clipboard
open suspend fun estimateGas(to: String, from: String? = null, value: String? = null, data: String? = null): BigInteger

Estimate gas for a transaction.

Link copied to clipboard
open suspend fun estimateL1Fee(to: String, from: String? = null, value: String? = null, data: String? = null, gasLimit: String? = null): BigInteger?

Estimate L1 data fee for a transaction (Base/OP Stack L2s). Returns null if the RPC does not support eth_estimateL1Fee (e.g. L1 chains). Prefer getL1FeeFromGasPriceOracle when EvmFeatures.opStackL1Fee is true.

Link copied to clipboard
open suspend fun getBalance(address: String, block: String = "latest"): BigInteger

Get the balance of an address in wei.

Link copied to clipboard
suspend fun getBlockByNumber(blockNumber: String = "latest", includeTransactions: Boolean = false): RpcBlock?

Get block by number.

Link copied to clipboard
suspend fun getBlockNumber(): BigInteger

Get the current block number.

Link copied to clipboard
open suspend fun getFeeHistory(blockCount: Int, newestBlock: String = "latest", rewardPercentiles: List<Int> = emptyList()): RpcFeeHistory

Get fee history for EIP-1559 fee estimation.

Link copied to clipboard
open suspend fun getGasPrice(): BigInteger

Get the current gas price.

Link copied to clipboard
open suspend fun getL1FeeFromGasPriceOracle(unsignedTxBytes: ByteArray): BigInteger?

Get L1 data fee from OP Stack GasPriceOracle predeploy (getL1Fee(bytes)). Uses the RLP-encoded unsigned transaction bytes as input; the oracle computes the L1 portion of the fee based on calldata size. Returns null on any failure.

Link copied to clipboard
open suspend fun getTransactionByHash(txHash: String): RpcTransaction?

Get transaction by hash.

Link copied to clipboard
open suspend fun getTransactionCount(address: String, block: String = "pending"): BigInteger

Get the transaction count (nonce) for an address.

Link copied to clipboard

Get transaction receipt by hash.

Link copied to clipboard
open suspend fun sendRawTransaction(signedTxData: String): String

Send a signed raw transaction.