idobn 9d89582f22 Chainging w3.eth.fee_history parameter so that the default is not None
It appears that fee_history must receive an array as the third parameter
and it's default None value does not work with some json-rpc nodes.
2022-02-04 20:13:00 +02:00

11 lines
342 B
Python

from web3 import Web3
async def fetch_base_fee_per_gas(w3: Web3, block_number: int) -> int:
base_fees = await w3.eth.fee_history(1, block_number, [])
base_fees_per_gas = base_fees["baseFeePerGas"]
if len(base_fees_per_gas) == 0:
raise RuntimeError("Unexpected error - no fees returned")
return base_fees_per_gas[0]