code: def transact(self, transaction=None):
          
          if transaction is None:
              transact_transaction = {}
          else:
              transact_transaction = dict(**transaction)
  
          if 'data' in transact_transaction:
              raise ValueError("Cannot set data in transact transaction")
  
          cf = self._contract_function
          if cf.address is not None:
              transact_transaction.setdefault('to', cf.address)
          if cf.web3.eth.defaultAccount is not empty:
              transact_transaction.setdefault('from', cf.web3.eth.defaultAccount)
  
          if 'to' not in transact_transaction:
              if isinstance(self, type):
                  raise ValueError(
                      "When using `Contract.transact` 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."
                  )
  
          if 'gas' not in transact_transaction:
              tx = transaction.copy()
              if 'passphrase' in tx:
                  tx.pop('passphrase')
              gas = cf.estimateGas(tx)
              transact_transaction['gas'] = gas
  
          return transact_with_contract_function(
              cf.address,
              cf.web3,
              cf.function_identifier,
              transact_transaction,
              cf.contract_abi,
              cf.abi,
              *cf.args,
              **cf.kwargs
          )
docs: Customize calling smart contract transaction functions to use `personal_sendTransaction`
          instead of `eth_sendTransaction` and to estimate gas limit. This function
          is largely copied from web3 ContractFunction with important addition.
  
          Note: will fallback to `eth_sendTransaction` if `passphrase` is not provided in the
          `transaction` dict.
  
          :param transaction: dict which has the required transaction arguments per
              `personal_sendTransaction` requirements.
          :return: hex str transaction hash