如何使用 web3js 版本 4.0.3 禁用 Metamask 窗口中的网站建议费用?

问题描述 投票:0回答:1

我使用了 web3 v1.10.0,我可以在 metmask 确认窗口中禁用网站建议费用。但将web3版本更新到4.0.3后,网站建议的费用又出现了。有人可以告诉我在最新版本中禁用网站建议费用的方法吗?

    const web3 = new Web3(window.ethereum);
    const contract = new web3.eth.Contract(erc20ABI, contractAddress);
    contract.methods
      .transfer(destinationAdrs, (depositAmt * 1000000).toString())
      .send({ from: sourceAdrs, gas: "21000", maxPriorityFeePerGas: null, maxFeePerGas: null })
      .then(function (receipt) {
        console.log(receipt);
      }).catch(function (error) {
        console.log(error);
      });

谢谢你

web3js
1个回答
0
投票

文档

1.x 中所有返回或接受 null 的 API 级别接口,请使用 4.x 中未定义

在 1.x 中,对于无类型、0x0 和 0x1 类型的交易, maxPriorityFeePerGas 和 maxFeePerGas 设置为 null。对于 0x2 类型 交易时,gasPrice 设置为 null。在 4.x 中,这些属性不再 除非提供,否则存在

因此,尝试将

maxPriorityFeePerGas
maxFeePerGas
更新为
undefined
而不是
null
。我认为这可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.