Skip to content

Commit 62c5bf3

Browse files
authored
use default max_priority_fee (#106)
1 parent 1b03cd7 commit 62c5bf3

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/ethers/transaction.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Ethers.Transaction do
1919
gas_price: nil,
2020
hash: nil,
2121
max_fee_per_gas: nil,
22-
max_priority_fee_per_gas: "0x0",
22+
max_priority_fee_per_gas: nil,
2323
nonce: nil,
2424
signature_r: nil,
2525
signature_s: nil,
@@ -58,7 +58,7 @@ defmodule Ethers.Transaction do
5858
@common_fillable_params [:chain_id, :nonce]
5959
@type_fillable_params %{
6060
legacy: [:gas_price],
61-
eip1559: [:max_fee_per_gas]
61+
eip1559: [:max_fee_per_gas, :max_priority_fee_per_gas]
6262
}
6363
@integer_type_values [
6464
:block_number,
@@ -231,6 +231,7 @@ defmodule Ethers.Transaction do
231231
defp fill_action(:chain_id, _tx), do: :chain_id
232232
defp fill_action(:nonce, tx), do: {:get_transaction_count, [tx.from, "latest"]}
233233
defp fill_action(:max_fee_per_gas, _tx), do: :gas_price
234+
defp fill_action(:max_priority_fee_per_gas, _tx), do: :max_priority_fee_per_gas
234235
defp fill_action(:gas_price, _tx), do: :gas_price
235236

236237
defp post_process([], [], acc), do: {:ok, Enum.into(acc, %{})}
@@ -251,6 +252,11 @@ defmodule Ethers.Transaction do
251252
end
252253
end
253254

255+
defp do_post_process(:max_priority_fee_per_gas, {:ok, v_int}) do
256+
# use latest max_priority_fee_per_gas from the chain as default
257+
{:ok, {:max_priority_fee_per_gas, Utils.integer_to_hex(v_int)}}
258+
end
259+
254260
defp do_post_process(key, {:ok, v_hex}) do
255261
{:ok, {key, v_hex}}
256262
end

test/ethers_test.exs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,25 @@ defmodule EthersTest do
546546
)
547547

548548
assert signed ==
549-
"0x02f8cd8205396480840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a002692d6fb9c645a9c16759ad577511d132c6976eacfaeca52f564771e4b80ddea075bcae22afa255d44387ef43fc6b005cc86529c6e99364e065736804f16c1bfc"
549+
"0x02f8d182053964843b9aca00840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a0da576ea4a1cf5979a34056d2fde083f6567430b2286e4985ffb9ea83df69c57fa070790ded792b1e55abd3fcc13202133289dfaba0fc96b476a76f488d69b2477d"
550+
end
551+
552+
test "returns signed transaction with custom max_priority_fee_per_gas" do
553+
signed =
554+
HelloWorldContract.set_hello("hi signed")
555+
|> Ethers.sign_transaction!(
556+
from: @from,
557+
gas: 10_000,
558+
max_fee_per_gas: 123_123_123,
559+
max_priority_fee_per_gas: 2_000_000_000,
560+
chain_id: 1337,
561+
nonce: 100,
562+
to: "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC",
563+
signer: Ethers.Signer.JsonRPC
564+
)
565+
566+
assert signed ==
567+
"0x02f8d1820539648477359400840756b5b38227109495ced938f7991cd0dfcb48f0a06a40fa1af46ebc80b864435ffe94000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096869207369676e65640000000000000000000000000000000000000000000000c001a054c7dd5c03757b3fa7c896bfb23f6bf3cf32aa21e3e53dbca00d447a673c033aa01e81b956fe27a1757f780a12570df243fc10c3a08b8647b301b1be15b376734e"
550568
end
551569

552570
test "raises in case of error" do

0 commit comments

Comments
 (0)