Temporary workaround until next web3.py release (5.X.X)

def patched_contractfunction_estimateGas(self, transaction=None, block_identifier=None):
    """Temporary workaround until next web3.py release (5.X.X)"""
    if transaction is None:
        estimate_gas_transaction = {}
    else:
        estimate_gas_transaction = dict(**transaction)

    if 'data' in estimate_gas_transaction:
        raise ValueError('Cannot set data in estimateGas transaction')
    if 'to' in estimate_gas_transaction:
        raise ValueError('Cannot set to in estimateGas transaction')

    if self.address:
        estimate_gas_transaction.setdefault('to', self.address)
    if self.web3.eth.defaultAccount is not empty:
        estimate_gas_transaction.setdefault('from', self.web3.eth.defaultAccount)

    if 'to' not in estimate_gas_transaction:
        if isinstance(self, type):
            raise ValueError(
                'When using `Contract.estimateGas` from a contract factory '
                'you must provide a `to` address with the transaction',
            )
        else:
            raise ValueError(
                'Please ensure that this contract instance has an address.',
            )

    return estimate_gas_for_function(
        self.address,
        self.web3,
        self.function_identifier,
        estimate_gas_transaction,
        self.contract_abi,
        self.abi,
        block_identifier,
        *self.args,
        **self.kwargs,
    )