0

我正在尝试设置交易的价格

根据文档:

value (in 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
        }
    }
4

1 回答 1

0

我找到了一种解决方法,似乎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-10-06T13:08:59.147 回答