Add eth_feeHistory based fee estimation - #270
Merged
Merged
Conversation
alisinabh
commented
Jul 29, 2026
Member
- New Ethers.fee_history/4 (+ bang variant) wrapping eth_feeHistory with all quantities decoded to integers; also usable in Ethers.batch/2 via {:fee_history, [block_count, newest_block, reward_percentiles]}
- New Ethers.estimate_fees/1 (+ bang variant): estimates EIP-1559 fees from the median of recent blocks' priority fees sampled at a percentile selected by :speed (:slow/:standard/:fast or a raw percentile), with max_fee_per_gas = 2 * next_base_fee + max_priority_fee_per_gas
- Transaction auto-fill now prices missing max_fee_per_gas / max_priority_fee_per_gas through estimate_fees instead of a margin over eth_gasPrice, falling back to the legacy estimation on RPC clients without eth_feeHistory support (the new adapter callback is optional)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces eth_feeHistory-based fee estimation to improve EIP-1559 transaction pricing, exposing a decoded Ethers.fee_history/4 API, a higher-level Ethers.estimate_fees/1 helper, and updating transaction auto-fill to prefer these estimates with a legacy fallback when unsupported.
Changes:
- Add
Ethers.fee_history/4(+fee_history!/4) and support batching via{:fee_history, [...]}. - Add
Ethers.estimate_fees/1(+estimate_fees!/1) to derive EIP-1559 fee caps from recent blocks’ priority fee samples and next base fee. - Update EIP-1559 transaction auto-fill to use
estimate_fees/1when supported, falling back to legacy gas price heuristics otherwise, and add test coverage.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ethers/fee_estimation_test.exs | Adds unit/integration tests for fee history decoding, fee estimation math, batching, and transaction auto-fill fallback behavior. |
| lib/ethers/transaction.ex | Switches EIP-1559 fee auto-fill to prefer estimate_fees/1 when available and retain legacy fill actions as fallback. |
| lib/ethers/rpc_client/adapter.ex | Adds optional eth_fee_history/4 callback to keep custom adapters backward compatible. |
| lib/ethers.ex | Implements fee_history/4, estimate_fees/1, decoding/post-processing, and percentile/median helpers. |
| CHANGELOG.md | Documents the new APIs and changed transaction auto-fill fee behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- New Ethers.fee_history/4 (+ bang variant) wrapping eth_feeHistory with all
quantities decoded to integers; also usable in Ethers.batch/2 via
{:fee_history, [block_count, newest_block, reward_percentiles]}
- New Ethers.estimate_fees/1 (+ bang variant): estimates EIP-1559 fees from the
median of recent blocks' priority fees sampled at a percentile selected by
:speed (:slow/:standard/:fast or a raw percentile), with
max_fee_per_gas = 2 * next_base_fee + max_priority_fee_per_gas
- Transaction auto-fill now prices missing max_fee_per_gas /
max_priority_fee_per_gas through estimate_fees instead of a margin over
eth_gasPrice, falling back to the legacy estimation on RPC clients without
eth_feeHistory support (the new adapter callback is optional)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012pKYp3j1ew76CY7HA2nBTF
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Quantities must be integers - hex encoded strings are rejected instead of being passed through, in line with the library convention of a single accepted representation per input: - block_count: positive integer only - newest_block: non-negative integer or one of the named block tags (latest/earliest/pending/safe/finalized) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012pKYp3j1ew76CY7HA2nBTF
Ethers.fee_history/4 called the optional eth_fee_history/4 adapter callback
directly, raising UndefinedFunctionError on RPC client adapters that do not
implement it. Guard with function_exported?/3 and return an error tuple
instead, keeping the {:ok, _} | {:error, _} contract.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012pKYp3j1ew76CY7HA2nBTF
alisinabh
force-pushed
the
fee-history-estimation
branch
from
July 30, 2026 03:09
47a455c to
638f0a6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.