Skip to content

Commit

Permalink
Get base fee per gas for next block
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaven committed Oct 13, 2023
1 parent 1cacd5a commit 88614e7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PyEthHelper/EthContractHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def DefaultFeeCalculator(
return maxPriorFee, ethGasPrice + maxPriorFee


def GetBaseFeePerGas(w3: Web3) -> int:
h = w3.eth.fee_history(1, 'latest')
return int(h['baseFeePerGas'][-1])


def _FillMessage(
w3: Web3,
gas: int,
Expand All @@ -171,7 +176,7 @@ def _FillMessage(
}
if privKey is not None:
maxPrioriyFee, maxFee = feeCalculator(
ethGasPrice=int(w3.eth.gas_price),
ethGasPrice=GetBaseFeePerGas(w3),
ethMaxPriorityFee=int(w3.eth.max_priority_fee),
)
msg['maxPriorityFeePerGas'] = maxPrioriyFee
Expand Down Expand Up @@ -206,7 +211,7 @@ def _SignTx(
)

if confirmPrompt:
baseFeePerGas = w3.eth.gas_price
baseFeePerGas = GetBaseFeePerGas(w3)
baseFeePerGasGwei = w3.from_wei(baseFeePerGas, 'gwei')
baseFee = baseFeePerGas * gas
baseFeeGwei = w3.from_wei(baseFee, 'gwei')
Expand Down

0 comments on commit 88614e7

Please sign in to comment.