3

I am testing whether transactions that I'm signing offline are accepted by the Ropsten network. I'm submitting the transactions using Web3.js ([email protected]) 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?

5
  • Try [email protected]. Commented Mar 29, 2019 at 19:36
  • That version indeed works! @goodvibration, do you know if it's a bug in the newer web3.js version?
    – econdepe
    Commented Mar 30, 2019 at 10:04
  • 1
    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. Commented Mar 30, 2019 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
    Commented Mar 30, 2019 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
    Commented Apr 7, 2019 at 22:28

2 Answers 2

1

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

0

I'm experiencing the same problem with [email protected], but in the end, this is the expected behaviour.

From what I can see, PromiEvent returns a TransactionReceipt. Since the transaction can't have a receipt without a confirmation, the promise doesn't resolve until it has 1 confirmation or it fails (gets rejected).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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