Is there any way I can tell whether a transaction hash is valid or not?
For eg,

0x2592cf699903e83bfd664aa4e339388fd044fe31643a85037be803a5d162729f is valid transaction Hash whereas 0x62720366ef403c9891e2bfbd5358ee3c8a57b113 is not.

How to test programmatically whether a transaction hash is valid or not using web3?

I wish to have a function like:

isValidTransactionHash(String txHash){
// if transaction hash is valid return true else false

I would try with web3.eth.getTransactionReceipt inside a try-catch block:

try {
  var txR = web3.eth.getTransactionReceipt("0x62720366ef403c9891e2bfbd5358ee3c8a57b11");
  if (txR.blockNumber == undefined)
    throw "transaction receipt not found";
catch(e) {
  console.log("invalid tx receipt: " + e);
  • But getTransactionteceipt is not meant for that. It returns null for any string starting with '0x' followed by any string of length 64. Like 0x1111111111111111111111111111111111111111111111111111111111111111 and 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa all are valid transaction hashes according ti this but actually they are not. – Prashant Prabhakar Singh May 4 '17 at 10:59
  • then simply check for some expected child, such as blockNumber. I added that to the example code. – Validity Labs - Sebastian May 4 '17 at 11:09
  • That's not the way man. See, getTransactionReceipt returns null for both an incorrect transaction Hash as well as the transaction that is not mined yet. So checking this way will declare all transaction Hashes which are valid but not yet mined as invalid.Hope you understand. – Prashant Prabhakar Singh May 4 '17 at 11:31
  • Did you test the code that I updated before posting my previous comment? I did and see it working. Please check again. – Validity Labs - Sebastian May 4 '17 at 11:48
  • I tested that. If you pass a transactionHash that is not yet mined (but transaction hash is valid), the value of txR will be null, and since in next line when you try to access blockNumber of null, this will give an error. and in this case, a valid transaction has is also declared as invalid. Please check the code with a valid but unmined transaction. – Prashant Prabhakar Singh May 4 '17 at 11:56

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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