1

I'm trying to send some ether and here is my code:

function sendEth(fromAddress, secret, toAddress, amount) {
  let params = {
    to: toAddress,
    from: fromAddress,
    value: web3.utils.toWei(amount + '', 'ether'),
    nonce: (new Date).getTime()
  };
  console.log(params);

  return Promise.all([web3.eth.estimateGas(params), web3.eth.getGasPrice()])
    .then((response) => {
      console.log(response);
      const estimatedGas = response[0];
      const gasPrice = response[1];
      params.gas = web3.utils.toHex(estimatedGas);
      params.gasPrice = web3.utils.toHex(gasPrice * 2); // Use 10% more gas than recommended
      params.value = params.value - (params.gasPrice * params.gas);
      // params.value = web3.utils.toWei(params.value - params.gas * params.gasPrice + '');
      // delete params.value;
      console.log(params);

      return web3.eth.accounts.signTransaction(params, secret);
    })
    .then((signedTx) => {
      console.log(signedTx);
      return web3.eth.sendSignedTransaction(signedTx.rawTransaction);
    })
    .then((response) => {
      console.log('response', response);
    })
    .catch((err) => {
      console.log('err', err);
    });
}

The signed transaction looks like:

{ messageHash: '0x0f974cbc64a581b4edb0bbd01d6c13f90bc632a5f91e8c15e938b13a5cbdf904',
  v: '0x2a',
  r: '0x957739758fcbe96c0f2fed2b69b486c99cacd6b3f338714c419fdcefa6074d19',
  s: '0x26030359b1bd16317ea6dab9d4da61fc77b7963fc22dc8072663747104a30dea',
  rawTransaction: '0xf87086016446eca4108306b6c2825208941608ff60df6884ad57dbedb6ebc41aebee4485d2880163457636ca25f0802aa0957739758fcbe96c0f2fed2b69b486c99cacd6b3f338714c419fdcefa6074d19a026030359b1bd16317ea6dab9d4da61fc77b7963fc22dc8072663747104a30dea' }

And it never actually hits the blockchain (I'm on ropsten). If I use https://ropsten.etherscan.io/pushTx to push the rawTransaction, it appears to succeed. But the transaction stays pending: https://ropsten.etherscan.io/tx/0x5ec8371471aa3159ea12e52fbcde552bd1cbf1a30534f6b44a3de983289a94df

What am I doing wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.