get_last_block_base_fee

Function

def get_last_block_base_fee(attempts=18):
    if latest_block := get_block('latest', False, attempts):
        base_fee = latest_block['baseFeePerGas']
        return float(round(web3.from_wei(base_fee, 'gwei'), 2))
    else:
        return -1

Description

  • Get the most recent block and it’s baseFeePerGas

  • Round it to nearest 2 decimal places

  • Return the amount as a float