【问题标题】:What could be a reason why Metamask won't display confirmation prompt even though transaction goes through?即使交易通过,Metamask 也不会显示确认提示的原因可能是什么?
【发布时间】:2021-07-05 17:22:45
【问题描述】:

我正在使用 Metamask 和 Web3 构建一个 dapp。合同中的一切似乎都可以正常工作,但是在我的 dapp .send() 功能中,如下面的与合同交互的功能似乎可以工作并且我收到了收据,但在此之前他们不会向用户显示确认提示接受交易。它会自动被接受。在某些时候,我确实得到了提示,但它停止了,我不确定这是合同错误还是前端错误。

谁能告诉我发生这种情况的潜在原因?

async function addImage() {
    await contract.methods
      .addImage(this.props.token, this.props.image)
      .send({
        from: accounts[0],
        gas: 6721975,
        gasPrice: "30000000",
      })
      .once("receipt", (receipt) => {
        console.log(receipt);
      })
      .catch((err) => {
        console.log(err);
      });
  }

【问题讨论】:

    标签: ethereum web3 web3js metamask


    【解决方案1】:

    好的,我刚刚意识到这可能是由于 Metamask 不再注入 web3。 如果我在我的代码中替换这一行

    const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    

    const web3 = new Web3(window.ethereum);
    

    然后就可以了。确认提示打开。对这两个库相互干扰以及为什么 web3 不会打开 Metamask 仍然有点困惑,但这是一个好的开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      相关资源
      最近更新 更多