-1

I trying to transfer ETH using ROPSTEN network, at first I had tested in MetaMask and both address are able to do the transaction without any problem. So, I start to try out in my application using web3@1.0.0-beta.34 , however the response are giving me Error: Returned error: insufficient funds for gas * price + value

What I guess is the error nothing do with the balance or gas, just not sure which part I doing not right.

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);
  }
}); 
TylerH
  • 20,799
  • 66
  • 75
  • 101
FeelRightz
  • 2,777
  • 2
  • 38
  • 73

1 Answers1

0

It works without error for me.

So possible reasons:

  1. Wrong gas price
  2. Wrong setamount
  3. You set privatekey with prefix 0x
StillFantasy
  • 1,677
  • 9
  • 21