I need to store the transaction details to my database. And here is my code:
var rawTx = {
nonce: nonce,
gas: estimate_gas,
to: contract_add,
value: '0x0',
data: dataField,
chainId: 4
};
web3.eth.accounts.signTransaction(rawTx, privateKey, function (err, hash) {
if (err) {
// Store err to database here
...
}
else {
web3.eth.sendSignedTransaction(hash.rawTransaction)
.then(res => {
console.log("DONE SENDING");
// Save res to Database here
...
})
.catch(error => {
console.log("FAILED SENDING");
// Save error to Database here
...
});
}
});
} catch (err) {
// Save err to Database here
...
}
The code is works for me, except when sendSignedTransaction
catch an error
that transaction was not mined in 750second. I know the transaction is still processing even this timeout error occurs.
But the critical problem here is further transactions will getting stuck in the pending, and get the same timeout error
in my code. These transaction need to wait in pending until the previous transactions success.
After the first transaction success, geth will continue process the pending transactions in node, but execute them without go through my code above, so I can't store the transaction result into my database now.
Is there any solution for this? Or there is some callback in geth when a transaction done so I could use this callback to store the transaction result?