使用 web3.js 进行交易有时会成功,有时会出错

Making transaction with web3.js sometime it make success and some time it gives errors

当我们进行任何交易时,每笔交易都需要 gas,所以我固定了多少 gas 才能成功交易,因为有时交易成功,有时会出错

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

Thanks in advance .


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

我刚刚制作了 gas in string 示例: 气体:'184000',

它对我有用。