Search code examples
node.jsethereumweb3js

Why do my transactions with web3.js sometimes return an 'insufficient funds' error?


When we are making any transaction then we need gas for every transaction so how much gas I fixed to making successful transactions because sometimes the transaction is successful, and sometimes it gives me an error:

Error: Returned error: insufficient funds for gas * price + value

exports.sendTransactions = (sender_account, to_account, p_key, value ) => {
  console.log("sendTRansactions", sender_account,  to_account , p_key , value );
  var admin = sender_account;
  var contract_address = to_account;
  var tx = {
    from: admin,
    to: contract_address,
    gas: 184000,
    data: "",
    value: value
  };
   return web3.eth.accounts.signTransaction(tx, p_key).then((hash) => {
     return web3.eth.sendSignedTransaction(hash.rawTransaction).then((receipt) => {
       return receipt
    }, (error) => {
      return error
      console.log(error);
      // reject(500);
    })
  }, (error) => {
    return error
    // reject(500);
  });
}

Solution

  • I just made gas is in string example: gas: '184000',

    and it working for me.