在decimal变量设置为18的ERC20令牌上发送事务时,必须将值乘以10^18。我不希望让dapp的用户将其值乘以该值。这将是非常不友好的用户。您如何解决此问题?如有任何帮助,我们不胜感激!
发布于 2021-07-21 06:21:46
您的代码可以为它们倍增。只需取输入值并乘以10^18即可。
<input type="text" name="to" value="0x123">
<input type="number" name="amount" value="5">const inputMock = {
to: '0x123',
value: 5
};
const myContract = new web3.eth.Contract(abiJson, contractAddress);
const txData = myContract.methods.transfer(
inputMock.to,
web3.utils.toWei(inputMock.value) // multiplies by 10^18 and returns the number as a string
);文档:https://web3js.readthedocs.io/en/v1.3.4/web3-utils.html#towei
https://stackoverflow.com/questions/68461908
复制相似问题