Skip to content

get max_priority_fee #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Enhancements

- Add support of getting current `max_priority_fee_per_gas`.

## v0.4.0 (2024-03-11)

### Breaking Changes
Expand Down
17 changes: 15 additions & 2 deletions lib/ethers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ defmodule Ethers do

@option_keys [:rpc_client, :rpc_opts, :signer, :signer_opts, :tx_type]
@hex_decode_post_process [
:estimate_gas,
:current_gas_price,
:current_block_number,
:get_balance
:estimate_gas,
:get_balance,
:max_priority_fee_per_gas
]
@rpc_actions_map %{
call: :eth_call,
Expand All @@ -85,6 +86,7 @@ defmodule Ethers do
get_logs: :eth_get_logs,
get_transaction_count: :eth_get_transaction_count,
get_transaction: :eth_get_transaction_by_hash,
max_priority_fee_per_gas: :eth_max_priority_fee_per_gas,
send: :eth_send_transaction
}

Expand Down Expand Up @@ -414,6 +416,17 @@ defmodule Ethers do
end
end

@doc """
Returns the current max priority fee per gas from the RPC API
"""
@spec max_priority_fee_per_gas(Keyword.t()) :: {:ok, non_neg_integer()}
def max_priority_fee_per_gas(opts \\ []) do
{rpc_client, rpc_opts} = get_rpc_client(opts)

rpc_client.eth_max_priority_fee_per_gas(rpc_opts)
|> post_process(nil, :max_priority_fee_per_gas)
end

@doc """
Fetches the event logs with the given filter.

Expand Down
6 changes: 6 additions & 0 deletions test/ethers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ defmodule EthersTest do
end
end

describe "max_priority_fee_per_gas" do
test "returns the correct max priority fee per gas" do
assert {:ok, 1_000_000_000} = Ethers.max_priority_fee_per_gas()
end
end

describe "current_block_number" do
test "returns the current block number" do
assert {:ok, n} = Ethers.current_block_number()
Expand Down