简体   繁体   English

在使用 transaction.wait() 时,我在 ether js 中收到一个事务被替换错误

[英]I am getting a transaction was replaced error in ether js while using transaction.wait()

I'm using ether.js to create a dapp.I want to input something in my database when something modifies on a blockchain.So I am using this for the check const receipt = await transaction.wait(1);我正在使用 ether.js 创建一个 dapp。我想在区块链上进行修改时在我的数据库中输入一些内容。所以我将其用于检查 const receipt = await transaction.wait(1); Once the transaction receipt is received it means it has been mined successfully.一旦收到交易收据,就意味着它已经被成功开采。 But the problem is when I am speeding up the transaction I get an error saying "TRANSACTION REPLACED" because I tried to send transaction again using the same nonce.The block is mined on the network but on frontend I'm getting this error.但问题是,当我加快交易速度时,我收到一条错误消息“TRANSACTION REPLACED”,因为我尝试使用相同的随机数再次发送交易。该块是在网络上开采的,但在前端我收到了这个错误。 How to handle this error?如何处理这个错误? This is the explanation of this error on docs.这是文档上此错误的解释。

This error is thrown when waiting for a transaction which has been replaced by another, by the sender submitting a second transaction with the same nonce, while the transaction was pending in the transaction pool.当等待已被另一个事务替换的事务时抛出此错误,发送方提交具有相同随机数的第二个事务,而事务在事务池中挂起。

Just found out what the core problem is - https://medium.com/the-capital/ethereum-speed-up-transactions-how-they-work-and-what-they-mean-for-dapps-6d4ba1068580刚刚发现核心问题是什么 - https://medium.com/the-capital/ethereum-speed-up-transactions-how-they-work-and-what-they-mean-for-dapps-6d4ba1068580

But their service is paid.但他们的服务是有偿的。

error from console log- index.ts:261来自控制台日志的错误 - index.ts:261

   Uncaught (in promise) Error: transaction was replaced [ See: https://links.ethers.org/v5-errors-TRANSACTION_REPLACED ] (cancelled=false, reason="repriced", replacement={"hash":"0x6fb9737ee9449817cb797104e64e023641e480f01b9a76721fbbd5d4bd8a25a5","type":2,"accessList":[],"blockHash":"0x95b11ed6cb7329fd9b475d324a6eb5de54cfb3ca79eac0c2ecdb0952a0021ad6","blockNumber":27034014,"transactionIndex":4,"confirmations":1,"from":"0xB157e57e493167491c8EE69681D89873a9D68B1C","gasPrice":{"type":"BigNumber","hex":"0x08896c4c12"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x08896c4c0b"},"maxFeePerGas":{"type":"BigNumber","hex":"0x08896c4c16"},"gasLimit":{"type":"BigNumber","hex":"0x6e80"},"to":"0x92265B57f08EF2F30dDd6d9CdCac1BD62C1A004b","value":{"type":"BigNumber","hex":"0x038d7ea4c68000"},"nonce":38,"data":"0xf340fa01000000000000000000000000b157e57e493167491c8ee69681d89873a9d68b1c","r":"0x96346c519bd65bbe2550a1396757e92f89c4d87246bf0bd4c3a8c8d315a6e78c","s":"0x332b38044b3efcd7bbe8e7b7e860024fb13306ce47c37a7b2168765c6e82f7e1","v":0,"creates":null,"chainId":80001}, hash="0x1a7442367d14df07d598aeb0ac9479926bee663637e11d535fa698cd9fd8f113", receipt={"to":"0x92265B57f08EF2F30dDd6d9CdCac1BD62C1A004b","from":"0xB157e57e493167491c8EE69681D89873a9D68B1C","contractAddress":null,"transactionIndex":4,"gasUsed":{"type":"BigNumber","hex":"0x6e80"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000008000100000000000008000000000000000000000000000000000000000000000000000000000800000000000000000000100048000004000000000000000080000000010000000000000000000000080000000000000000000000000000000000000000000000000080001000080000000000000000000200000000000000000000000000000004000000400000100000000000000004000000000000000020001000000000000000000000000800000108040000000000000000000000000000000000000000000000000000000400000000000100000","blockHash":"0x95b11ed6cb7329fd9b475d324a6eb5de54cfb3ca79eac0c2ecdb0952a0021ad6","transactionHash":"0x6fb9737ee9449817cb797104e64e023641e480f01b9a76721fbbd5d4bd8a25a5","logs":[{"transactionIndex":4,"blockNumber":27034014,"transactionHash":"0x6fb9737ee9449817cb797104e64e023641e480f01b9a76721fbbd5d4bd8a25a5","address":"0x0000000000000000000000000000000000001010","topics":["0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4","0x0000000000000000000000000000000000000000000000000000000000001010","0x000000000000000000000000b157e57e493167491c8ee69681d89873a9d68b1c","0x00000000000000000000000092265b57f08ef2f30ddd6d9cdcac1bd62c1a004b"],"data":"0x00000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000004a10eca800d2aa93000000000000000000000000000000000000000000000000035801792bb0d0000000000000000000000000000000000000000000000000004a0d5f295c0c2a93000000000000000000000000000000000000000000000000035b8ef7d0775000","logIndex":10,"blockHash":"0x95b11ed6cb7329fd9b475d324a6eb5de54cfb3ca79eac0c2ecdb0952a0021ad6"},{"transactionIndex":4,"blockNumber":27034014,"transactionHash":"0x6fb9737ee9449817cb797104e64e023641e480f01b9a76721fbbd5d4bd8a25a5","address":"0x92265B57f08EF2F30dDd6d9CdCac1BD62C1A004b","topics":["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c"],"data":"0x000000000000000000000000b157e57e493167491c8ee69681d89873a9d68b1c00000000000000000000000000000000000000000000000000038d7ea4c68000","logIndex":11,"blockHash":"0x95b11ed6cb7329fd9b475d324a6eb5de54cfb3ca79eac0c2ecdb0952a0021ad6"},{"transactionIndex":4,"blockNumber":27034014,"transactionHash":"0x6fb9737ee9449817cb797104e64e023641e480f01b9a76721fbbd5d4bd8a25a5","address":"0x0000000000000000000000000000000000001010","topics":["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63","0x0000000000000000000000000000000000000000000000000000000000001010","0x000000000000000000000000b157e57e493167491c8ee69681d89873a9d68b1c","0x000000000000000000000000be188d6641e8b680743a4815dfa0f6208038960f"],"data":"0x0000000000000000000000000000000000000000000000000003af513ed2bf800000000000000000000000000000000000000000000000004a149bf93fa86f93000000000000000000000000000000000000000000001d2f81f5cd2c083658f80000000000000000000000000000000000000000000000004a10eca800d5b013000000000000000000000000000000000000000000001d2f81f97c7d47091878","logIndex":12,"blockHash":"0x95b11ed6cb7329fd9b475d324a6eb5de54cfb3ca79eac0c2ecdb0952a0021ad6"}],"blockNumber":27034014,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x06733e"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x08896c4c12"},"status":1,"type":2,"byzantium":true}, code=TRANSACTION_REPLACED, version=providers/5.6.8)
at Logger.makeError (index.ts:261:1)
at Web3Provider.<anonymous> (base-provider.ts:1372:1)
at Generator.next (<anonymous>)
at fulfilled (base-provider.ts:1:1)





 if (typeof window.ethereum !== "undefined" && logInState === true) {
      const provider = new ethers.providers.Web3Provider(window.ethereum);
      const signer = provider.getSigner();

      const contract = new ethers.Contract(gambleAddress, Gamble.abi, signer);
      const transaction = await contract.deposit(acc, {
        value: ethers.utils.parseEther(matic.toString()),
      });



 const receipt = await transaction.wait(1);
  console.log(receipt);
  if (receipt) {
    updateDepositInDb();
  } else {
    alert("transaction failed");
  }

You should surround your code with try catch to handle exceptions.你应该用 try catch 包围你的代码来处理异常。

You may refer to the link below to find out how to detect replacement transactions in your scenarios.您可以参考下面的链接,了解如何在您的场景中检测替换交易。

https://blog.ricmoo.com/highlights-ethers-js-may-2021-2826e858277d https://blog.ricmoo.com/highlights-ethers-js-may-2021-2826e858277d

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法弄清楚为什么在处理事务时出现 VM 异常:恢复错误 - Cannot figure out why I am getting VM Exception while processing transaction: revert error 为什么在angular js中使用resolve时出现错误? - why i am getting error while using resolve in angular js? 事务恢复:function 在使用 ether.js 进行测试时返回了意外的数据量(uniswapv2router.swapExactTokensForTokens 函数) - Transaction reverted: function returned an unexpected amount of data while testing with ether.js (uniswapv2router.swapExactTokensForTokens function) 我在使用 nodemailer 时遇到错误 - i am getting error while using nodemailer 我正在尝试使用 web3 在 Pancakeswap 上执行交换,但在计算交易成本时出现错误 - I am trying to execute a swap on Pancakeswap using web3, but I get an error when calculating transaction cost 在反应 js 中使用 onChange 时我没有收到合成事件 - I am not getting synthetic event while using in onChange in react js 当我测试我的可靠性代码时,我收到“AssertionError: Expected transaction to be reverted with Username” - I am getting "AssertionError: Expected transaction to be reverted with Username " when I am testing my solidity code 在 app.js 中导入 js 文件时出现未知文件扩展名错误,使用类型:package.json 中的模块 - I am getting unknown file extension error while importing a js file in app.js, using type: module in package.json 第一次使用 React-app 时出现错误,错误是 core-js-pure@3.6.5 postinstall - I am getting error while using React-app first time, Error is core-js-pure@3.6.5 postinstall 在运行使用solidity 智能合约的next.js 应用程序时,出现“无法读取未定义的属性”错误 - While running my next.js app that is using solidity smart contracts, I am getting "Cannot read properties of undefined" error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM