使用web3.py调用合约函数失败,但是使用remix调用没问题。这是咋回事?

我用remix部署了一个合约,我在remix上调用合约的函数都没问题,但是使用web3.py来调合约函数的时候,就不成功,总是提示:execution reverted: failed to execute message。 这是怎么回事呢? python代码:

deadline = int(time.time()) + 300
 func = self.arb_contract.functions.swap(address,deadline)
 tx = {
                'from': address,
                'value': self.w3.toWei(value, 'ether'),
                'gas': 250000,
                'gasPrice': self.w3.eth.gas_price,
                'nonce': self.w3.eth.getTransactionCount(address)

   }
  transaction = func.buildTransaction(tx)
  signed_tx = self.w3.eth.account.sign_transaction(transaction, private_key)
  tx_hash = self.w3.eth.sendRawTransaction(signed_tx.rawTransaction).hex()
  self.w3.eth.waitForTransactionReceipt(tx_hash)

在remix上调用的结果: image.png

使用python调用的结果: image.png

请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,4274 浏览
  • peterchen145 提出于 2021-04-28 11:11