The following includes a null Tx id:
web3.eth.getTransaction('0x2fc36f9c6593bc1232b3466832c6ee38b5b2b3b4a54be3f6c68fb06e8d82e452', function(error, result){
if (!error) {
console.log(result.blockNumber)
}
})
You would expect this to log null or undefined, but it throws in Web3.js 1.2.1. This makes it impossible to use getTransaction with polling to see if a transaction is confirmed.
checkTx()
function checkTx() {
web3.eth.getTransaction('0x2fc36f9c6593bc1232b3466832c6ee38b5b2b3b4a54be3f6c68fb06e8d82e452')
.then((result) => {
if (result.blockNumber != null) {
console.log(result.value)
} else {
console.log('Not confirmed.')
setTimeout(() => { checkTx() }, 1000)
}
})
}
In both case you get this error when the Tx blockNumber is null: TypeError: Cannot read property 'blockNumber' of null
How can I check that a transaction id is confirmed by polling if I can't evaluate the property of the blockNumber
?