@@ -51,28 +51,24 @@ async def _estimate_gas(w3: "Web3", tx: TxParams) -> Awaitable[int]:
51
51
return await w3 .eth .estimate_gas (tx ) # type: ignore
52
52
53
53
54
- async def _gas_price (w3 : "Web3" , tx : TxParams ) -> Awaitable [Optional [Wei ]]:
55
- return await w3 .eth .generate_gas_price (tx ) # type: ignore
56
-
57
-
58
- async def _max_fee_per_gas (w3 : "Web3" , tx : TxParams ) -> Awaitable [Wei ]:
54
+ async def _max_fee_per_gas (w3 : "Web3" , _tx : TxParams ) -> Awaitable [Wei ]:
59
55
block = await w3 .eth .get_block ("latest" ) # type: ignore
60
56
return await w3 .eth .max_priority_fee + (2 * block ["baseFeePerGas" ]) # type: ignore
61
57
62
58
63
- async def _max_priority_fee_gas (w3 : "Web3" , tx : TxParams ) -> Awaitable [Wei ]:
59
+ async def _max_priority_fee_gas (w3 : "Web3" , _tx : TxParams ) -> Awaitable [Wei ]:
64
60
return await w3 .eth .max_priority_fee # type: ignore
65
61
66
62
67
- async def _chain_id (w3 : "Web3" , tx : TxParams ) -> Awaitable [int ]:
63
+ async def _chain_id (w3 : "Web3" , _tx : TxParams ) -> Awaitable [int ]:
68
64
return await w3 .eth .chain_id # type: ignore
69
65
70
66
71
67
TRANSACTION_DEFAULTS = {
72
68
"value" : 0 ,
73
69
"data" : b"" ,
74
70
"gas" : _estimate_gas ,
75
- "gasPrice" : _gas_price ,
71
+ "gasPrice" : lambda w3 , tx : w3 . eth . generate_gas_price ( tx ) ,
76
72
"maxFeePerGas" : _max_fee_per_gas ,
77
73
"maxPriorityFeePerGas" : _max_priority_fee_gas ,
78
74
"chainId" : _chain_id ,
@@ -112,9 +108,8 @@ async def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxPara
112
108
"""
113
109
if w3 is None, fill as much as possible while offline
114
110
"""
115
- strategy_based_gas_price = await w3 .eth .generate_gas_price ( # type: ignore
116
- transaction
117
- )
111
+ strategy_based_gas_price = w3 .eth .generate_gas_price (transaction )
112
+
118
113
is_dynamic_fee_transaction = strategy_based_gas_price is None and (
119
114
"gasPrice" not in transaction # default to dynamic fee transaction
120
115
or any_in_dict (DYNAMIC_FEE_TXN_PARAMS , transaction )
@@ -138,7 +133,12 @@ async def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxPara
138
133
raise ValueError (
139
134
f"You must specify a '{ key } ' value in the transaction"
140
135
)
141
- default_val = await default_getter (w3 , transaction )
136
+ if key == "gasPrice" :
137
+ # `generate_gas_price()` is on the `BaseEth` class and does not
138
+ # need to be awaited
139
+ default_val = default_getter (w3 , transaction )
140
+ else :
141
+ default_val = await default_getter (w3 , transaction )
142
142
else :
143
143
default_val = default_getter
144
144
0 commit comments