apply_estimated_gas

Function

def apply_estimated_gas(tx, attempts=18):
    while attempts > 0:
        try:
            if 'gas' not in tx:
                tx['gas'] = web3.eth.estimate_gas(tx)
        except Exception as e:
            logging.debug(e)
            attempts -= 1
            time.sleep(1)
        else:
            return tx

Description

  • Loop while there are attempts remaining

  • Add a gas key/value with the gas required to run all functions for the transaction

  • Return the transaction