【问题标题】:How to set the Eth price with a transaction with web3js如何通过 web3js 交易设置 Eth 价格
【发布时间】:2021-11-23 16:58:52
【问题描述】:

我正在尝试设置交易价格

根据文档:

值(以 wei 为单位):从发送者转移到接收者的 Wei 数量。

但是当我输入这个值时:(对于 0.04eth)-> 我在 metamask 中得到 73 eth :)

(我在rinkeby网络上)

这是我的代码:

window.contract = await new web3.eth.Contract(contractABI.abi, contractAddress);//loadContract();
     const transactionParameters = {
        to: contractAddress, // Required except during contract publications.
        from: window.ethereum.selectedAddress, // must match user's active address.
        'data': window.contract.methods.mint(window.ethereum.selectedAddress,number).encodeABI(),
        value: String(40000000000000000) 
      };
    try {
        const txHash = await window.ethereum
            .request({
                method: 'eth_sendTransaction',
                params: [transactionParameters],
            });
        return {
            success: true,
            status: " Check out your transaction on Etherscan: https://ropsten.etherscan.io/tx/" + txHash
        }
    } catch (error) {
      console.log(error);
        return {
            success: false,
            status: " Something went wrong: " + error.message
        }
    }

【问题讨论】:

    标签: web3 nft ether


    【解决方案1】:

    我找到了一种解决方法,似乎eth_sendTransaction 不能很好地处理该值。通过这样使用它现在可以工作了。

    window.contract.methods.mint(window.ethereum.selectedAddress,  1).send({
             from: window.ethereum.selectedAddress, value: web3.utils.toWei(String(0.05*number),"ether")});
    

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 1970-01-01
      • 2022-11-04
      • 2018-09-12
      • 2021-11-23
      • 1970-01-01
      • 2016-01-07
      • 2022-12-14
      • 2018-09-13
      相关资源
      最近更新 更多