I'm building a block explorer using blockchain.info and their API https://github.com/blockchain/api-v1-client-php/blob/master/docs/blockexplorer.md

but what I don't understand is, what is the best way to recognize if the user is searching for an address or a block hash, or what ever. how do the other block explorers do that? They allow to search for all of those in the same search box.

Thanks for any help !

1 Answer 1


Block explorers I've seen typically accept the following inputs:

  • Bitcoin address: 25-34 alphanumeric characters.

  • Block height: decimal number, up to let's say 10 digits

  • Block hash: 64 hex digits (0-9, a-f), representing a 256-bit number

  • Transaction ID: 64 hex digits

So it's easy to recognize a Bitcoin address or block height with a simple regex.

They can't tell apart a block hash from a transaction ID, because in principle any given 256-bit number could be the hash of either (or neither). So when a string of 64 hex digits is input, they simply search for it as block hash and as a transaction ID, and if one of them is found, they return the appropriate information. It's overwhelmingly improbable that the same string could be the hash of a valid block and of a valid transaction, so there isn't really any need to handle the possibility that both are found.

They could do some minor optimizations: for instance, if the string starts with a bunch of zeros, it's more likely to be a block hash, so maybe they search that table first.

  • Í would like to, if I may, to add to first bullet point: when on production, addresses begin with „1“ or „3“ ... Feb 5, 2018 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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