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?
Best Answer
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