1

I am testing whether transactions that I'm signing offline are accepted by the Ropsten network. I'm submitting the transactions using Web3.js (web3@1.0.0-beta.51) as follows:

I connect to an INFURA node, and then use web3.eth.sendSignedTransaction. According to the documentation, this should return a PromiEvent. However, the events emitted by the submission are not captured and the promise never resolves. The transaction is submitted to the network nonetheless and is valid (it's a simple transaction sending funds from one non-contract account to another). One can find it in any blockexplorer, like for instance etherscan.

The code in 1 does not behave as expected:

const Web3 = require('web3');
const Tx = require('ethereumjs-tx')

const web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/my_Infura_key"));
;
const privateKey = new Buffer(a_private_key_controlling_an_account_with_say_more_than_1_ether, 'hex')

const rawTx = {
  nonce: '0x00', // adjust accordingly if it's not the first transaction by the account
  gasPrice: '0x09184e72a000',
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000',
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
  chainId: 3
}

const tx = new Tx(rawTx);
tx.sign(privateKey);

const serializedTx = tx.serialize();

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);

// result: the code simply hangs without printing anything

The code above just hangs, because the promise returned by sendSignedTransaction is never resolved. No event is received either, so the .on('receipt') is never triggered. However the transaction is successfully submitted to the network, and the sender account is debited with around 0.21 ether (the price of the gas since there is no value transmitted). So the problem is not with the submission, but rather with the PromiEvent that web3.eth.sendSignedTransaction returns.

I suspect this problem could be related to an issue of INFURA nodes with events discussed somewhere else, but I don't know if that is the case. I can't check what would happen had web3 been instantiated through a local geth node. At any rate I haven't seen anywhere in the documentation 1 where they mention that PromiEvent only works with certain instances of Web3.

Anyone has any idea of why this behavior is happening?

  • Try web3@1.0.0-beta.34. – goodvibration Mar 29 at 19:36
  • That version indeed works! @goodvibration, do you know if it's a bug in the newer web3.js version? – econdepe Mar 30 at 10:04
  • I know that there have been various problems and issues reported for versions newer than v37. I personally use v34, so I was able vouch for it. You can try v35, v36 or v37, which may also work for you. I'm pretty sure that v38 onward are not really stable. – goodvibration Mar 30 at 10:24
  • 1
    Mmhh, I was thinking whether I should open an issue in their github, but it may not be worth it then. Thanks for the advice on trying an older version of the package! – econdepe Mar 30 at 22:39
  • I'm having the same issue. And using .then(console.log) instead of .on('receipt', console.log) gives the same result – Jonah Apr 7 at 22:28
0

i had the same problem here and i found a temporary issue:

The problem was with the web3 patch, i was using the version "1.0.0-beta.52". So, i returned to "1.0.0-beta.37" and everything worked.

I dont know why didnt worked with the new version... by the way

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.