Skip to content

Commit 1b03cd7

Browse files
authored
get max_priority_fee (#105)
1 parent ea266cb commit 1b03cd7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Enhancements
6+
7+
- Add support of getting current `max_priority_fee_per_gas`.
8+
39
## v0.4.0 (2024-03-11)
410

511
### Breaking Changes

lib/ethers.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ defmodule Ethers do
7070

7171
@option_keys [:rpc_client, :rpc_opts, :signer, :signer_opts, :tx_type]
7272
@hex_decode_post_process [
73-
:estimate_gas,
7473
:current_gas_price,
7574
:current_block_number,
76-
:get_balance
75+
:estimate_gas,
76+
:get_balance,
77+
:max_priority_fee_per_gas
7778
]
7879
@rpc_actions_map %{
7980
call: :eth_call,
@@ -85,6 +86,7 @@ defmodule Ethers do
8586
get_logs: :eth_get_logs,
8687
get_transaction_count: :eth_get_transaction_count,
8788
get_transaction: :eth_get_transaction_by_hash,
89+
max_priority_fee_per_gas: :eth_max_priority_fee_per_gas,
8890
send: :eth_send_transaction
8991
}
9092

@@ -414,6 +416,17 @@ defmodule Ethers do
414416
end
415417
end
416418

419+
@doc """
420+
Returns the current max priority fee per gas from the RPC API
421+
"""
422+
@spec max_priority_fee_per_gas(Keyword.t()) :: {:ok, non_neg_integer()}
423+
def max_priority_fee_per_gas(opts \\ []) do
424+
{rpc_client, rpc_opts} = get_rpc_client(opts)
425+
426+
rpc_client.eth_max_priority_fee_per_gas(rpc_opts)
427+
|> post_process(nil, :max_priority_fee_per_gas)
428+
end
429+
417430
@doc """
418431
Fetches the event logs with the given filter.
419432

test/ethers_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ defmodule EthersTest do
2727
end
2828
end
2929

30+
describe "max_priority_fee_per_gas" do
31+
test "returns the correct max priority fee per gas" do
32+
assert {:ok, 1_000_000_000} = Ethers.max_priority_fee_per_gas()
33+
end
34+
end
35+
3036
describe "current_block_number" do
3137
test "returns the current block number" do
3238
assert {:ok, n} = Ethers.current_block_number()

0 commit comments

Comments
 (0)