【问题标题】:Web3 : transfer ETH went wrongWeb3:转账 ETH 出错
【发布时间】:2020-01-23 22:02:36
【问题描述】:

我尝试使用 ROPSTEN 网络转移 ETH,起初我在 MetaMask 中进行了测试,两个地址都能够进行交易没有任何问题。所以,我开始在我的应用程序中尝试使用 web3@1.0.0-beta.34 ,但是响应给了我 错误:返回错误:gas * price + value 资金不足

我猜这个错误与天平或气体无关,只是不确定我做错了哪一部分。

const web3 = new Web3('https://ropsten.infura.io:443'); 
var count = await web3.eth.getTransactionCount(publicaddress);
var gasPrices = await this.getCurrentGasPrices();
var rawTransaction = {
  "from": selectedWallet.publicaddress,
  "nonce": count,
  "gasPrice": gasPrices.low * 100000000,
  "gas": web3.utils.toHex("519990"),
  "to": recipientaddress,
  "value": web3.utils.toWei(new Web3.utils.BN(setamount), 'ether'),
};
var privKey = new Buffer(privatekey,'hex');
var tx = new Tx(rawTransaction,{'chain': 'ropsten'});
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), (err, hash) =>{
  if (!err){ //SUCCESS
      console.log("success", hash);
  }else{
      console.log(err);
  }
}); 

【问题讨论】:

    标签: ethereum web3 web3js ether


    【解决方案1】:

    它对我来说没有错误。

    所以可能的原因:

    1. gas 价格错误
    2. 设置数量错误
    3. 您将privatekey 设置为前缀0x

    【讨论】:

      猜你喜欢
      • 2021-01-22
      • 2022-01-15
      • 2019-09-01
      • 2022-08-12
      • 2018-07-22
      • 2023-01-13
      • 2022-11-19
      • 2022-07-10
      • 2021-09-04
      相关资源
      最近更新 更多