转移以太币返还"insufficient funds for gas * price + value"



我尝试使用 ROPSTEN 网络转移 ETH,起初我在小狐狸钱包中进行了测试,两个地址都能够毫无问题地进行交易。因此,我开始使用web3@1.0.0-beta.34在我的应用程序中尝试,但是响应给了我错误:返回的错误:gas资金不足*价格+价值

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

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);
}
}); 

它对我来说没有错误。

所以可能的原因:

  1. 错误的汽油价格
  2. 错误的设置金额
  3. 使用前缀设置privatekey0x

最新更新