Debugging sendSignedTransaction Errors

I am running a node script to initiate transactions via Web3 1.0 (beta 55), and using sendSignedTransaction to broadcast the Tx to Infura. Every once in a while, I am getting an instant error that makes no sense. When it errors, it doesn’t get submitted, but if I try again five seconds later, it will always work. What could be going on at the node level to trigger this? I never get errors when connected to a local node, but that is probably because I’m using a different method as I’m already logged in.

If nobody knows, can I just resubmit on an error right away in the .on routine? I ask because it happens so rarely it is hard to test the behavior, and I haven’t been able to replicate. My suspicion is that it is a websocket disruption.

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
     	    .once("confirmation", function() {
     	      	console.log('*** Transaction Confirmed ***')
     	    })
     	    .on("error", function() {
     	        console.log('*** Error ***')
     	    })
1 Like

Can you change your code to log the actual error?

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
 	    .once("confirmation", function() {
 	      	console.log('*** Transaction Confirmed ***')
 	    })
 	    .on("error", console.error)

As for resubmitting, yes you should be able to resubmit in the .on handler, but should implement some sort of exponential backoff if the errors keep happening to avoid being rate-limited.

1 Like

Yes, I tried that (as that’s the default), but it doesn’t print the error in the console. The same goes for the other console default functions. Should I be looking somewhere else for this log?

should implement some sort of exponential backoff if the errors keep happening to avoid being rate-limited.

Good point. I just planned to do it once or twice as that should be enough.

Hi everyone…
I’m new here