2

我想使用 MetaMask 发送 ETH 或 ERC20 令牌
我正在使用的以下脚本抛出错误,

RPC 错误:错误:0.001 数字的无效交易值必须在 wei 中

const method = 'eth_sendTransaction'
const parameters = [{
    from: account,
    to: to,
    value: 0.001
}]
const from = account
const payload = {
    method: method,
    params: parameters,
    from: from,
}
web3.currentProvider.sendAsync(payload, function (err, response) {

}); 
4

1 回答 1

0
In Ether, the smallest unit of the currency is wei, and 1 ETH === 10^18 wei 

var weiValue = web3.utils.toWei('1', 'ether'); // 1 以太
控制台.log(weiValue);//1000000000000000000

于 2020-03-17T08:10:29.163 回答