From c568fd3934f73d1649876dcd7b925843076101a2 Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Fri, 16 Sep 2022 19:23:34 +0100 Subject: [PATCH] fix(providers): don't default to "latest" block ID for `eth_estimateGas` (#1657) * Don't default to 'latest' block ID for eth_estimateGas * Add changelog entry * Amend comment --- CHANGELOG.md | 1 + ethers-providers/src/provider.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 939c4189..4bbad810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Unreleased +- Stop defaulting to the `"latest"` block in `eth_estimateGas` params [#1657](https://github.com/gakonst/ethers-rs/pull/1657) - Fix geth trace types for debug_traceTransaction rpc - Fix RLP decoding of legacy `Transaction` - Fix RLP encoding of `TransactionReceipt` [#1661](https://github.com/gakonst/ethers-rs/pull/1661) diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 0aec2f7b..0b26489e 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -574,8 +574,14 @@ impl Middleware for Provider

{ block: Option, ) -> Result { let tx = utils::serialize(tx); - let block = utils::serialize(&block.unwrap_or_else(|| BlockNumber::Latest.into())); - self.request("eth_estimateGas", [tx, block]).await + // Some nodes (e.g. old Optimism clients) don't support a block ID being passed as a param, + // so refrain from defaulting to BlockNumber::Latest. + let params = if let Some(block_id) = block { + vec![tx, utils::serialize(&block_id)] + } else { + vec![tx] + }; + self.request("eth_estimateGas", params).await } async fn create_access_list(