user59311: how do sites like https://blockexplorer.com determine if the input (see inputbox in the header of https://blockexplorer.com ) is an address, transaction ID or block ID?
I want to write something similar myself on my local machine, where I run a full node and have access to bitcoind RPC. I need to know how to direct the input given one box can be 3 things.

user12983: There is no way to determine from a hash alone if it represents an address, transaction ID or block ID. All three could be any valid SHA-256 number, and vice versa.
In order to determine Blockchain explorers sites likely do something like the following pseudocode, where blockDB, transactionDB, and addressDB represent all known block IDs, transaction IDs, and addresses respectively.
if ( blockDB.contains ( input ) )
{
  // this is block hash
}
else if ( transactionDB.contains ( input ) )
{
  // this is transaction id
}
else if ( addressDB.contains ( input ) )
{
  // this is address
}
else
{
  // error! unknown input
}


user51948: As outlined in the pseudocode in amaclin's answer, a block explorer website would simply check to see if they can find the hash/txid/address in their database, then they will know what type of input it is.
You can't directly perform this check via one bitcoin core RPC call, you would have to write a script of some sort to perform the 3 checks to figure out which type of input you were given. You can first check for a valid block hash using the getblock RPC, and if that failed you know its not a block hash. Next you would have to have txindex enabled on your node to allow yourself to query txids using the gettransaction / getrawtransaction RPCs (because by default the node only indexs transactions which are related to your wallet). And then to check if its a valid address, you can use the validateaddress RPC call. If all of those failed, you know the input is invalid.

59311: <p>how do sites like <a href="https://blockexplorer.com" rel="nofollow noreferrer">https://blockexplorer.com</a> determine if the input (see inputbox in the header of <a href="https://blockexplorer.com" rel="nofollow noreferrer">https://blockexplorer.com</a> ) is an address, transaction ID or block ID?</p>

<p>I want to write something similar myself on my local machine, where I run a full node and have access to bitcoind RPC. I need to know how to direct the input given one box can be 3 things.</p>
 12983: <p>There is no way to determine from a hash alone if it represents an address, transaction ID or block ID. All three could be any valid SHA-256 number, and vice versa.</p>

<p>In order to determine Blockchain explorers sites likely do something like the following pseudocode, where <code>blockDB</code>, <code>transactionDB</code>, and <code>addressDB</code> represent all known block IDs, transaction IDs, and addresses respectively.</p>

<pre><code>if ( blockDB.contains ( input ) )
{
  // this is block hash
}
else if ( transactionDB.contains ( input ) )
{
  // this is transaction id
}
else if ( addressDB.contains ( input ) )
{
  // this is address
}
else
{
  // error! unknown input
}
</code></pre>
 51948: <p>As outlined in the pseudocode in amaclin's answer, a block explorer website would simply check to see if they can find the hash/txid/address in their database, then they will know what type of input it is.</p>

<p>You can't directly perform this check via one bitcoin core RPC call, you would have to write a script of some sort to perform the 3 checks to figure out which type of input you were given. You can first check for a valid block hash using the <code>getblock</code> RPC, and if that failed you know its not a block hash. Next you would have to have <code>txindex</code> enabled on your node to allow yourself to query txids using the <code>gettransaction</code> / <code>getrawtransaction</code> RPCs (because by default the node only indexs transactions which are related to your wallet). And then to check if its a valid address, you can use the <code>validateaddress</code> RPC call. If all of those failed, you know the input is invalid.</p>
