If the transaction outputs associated to the public key has not been spent, then finding the funds associated with that public key will mostly be a trial and error method.
Searching in outputs
Most outputs in Bitcoin send funds to an address that is the hash of the public key. Pay-to-public-key (P2PK) is the only standard output that sends funds directly to the public key, but is rarely used. Now, I said finding funds from the outputs is a trial and error method, because you do not know what type of address is being used by the person who controls that public key. He may be using P2PKH (addresses starting with 1), P2WPKH (addresses starting with bc1) or P2SH-P2WPKH (addresses starting with 3). You would need to generate those addresses from the public key and see if it matches to that using any explorers. Also, the user might have used the uncompressed public key version to generate the P2PKH address, so you would need to search for that as well.
Moreover, if funds are controlled in multi-sig addresses, where one of the public key involved is the one you know, it is impossible to calculate the address without knowing the other public keys AND the spending condition (m-of-n).
Searching in inputs
However, if the funds are spent, the task is 'easier'. You just have to go through all the inputs of all the transactions, and check that the public key was used to satisfy unlocking condition. Most inputs will have their scriptSig (witness data in case of SegWit) as <sig><pub_key>. You can match the public key against the one that is mentioned in the scriptSig.
This is also helpful with analyzing the public key for multi-sig transaction, if that public key was involved in the spending. However, there is still a gap involved. If the public key was say used in 2-of-3 multi-sig, and the transaction was spent with the other two keys, then there is no way of knowing, whether that public key was involved in that transaction at all.
Thanks but I am aware of the facts mentioned in your reply. What I want to know is how to query the blockchain (if possible) using the raw HEX public key as a single search term. As you said, blockchain explorers only allow searching for the hashed public key / address ID, TX id, etc. Perhaps some code is out there but cannot find anything on GitHub or Google. – RobertH – 2019-06-23T01:27:33.930
The proposed Python script code doesn't fit your requirements? You could combine
bitcoin-address-from-public-key.pywithbitcoin-get-address-balance.pyto directly askblockchain.infofrom command line ! I'm going to add this to the answer. – circulosmeos – 2019-06-23T11:54:55.103Yes, thank you so much. Your script is great and it does the job.It asks the blockchain directly and you are right this can only be done from command line. I will mark your answer :) The only issues I have is 1) when I enter the public key above it returns a diff address
18eCccERvefbyrgL15eK2exczQge9gQit5. And 2) how do I combine your two scripts on Ubuntu, in python so I can reproduce your resultstotal_received = 1.57390781 Bitcoin final_balance = 0 BitcoinI can see you used Windows in your example? – RobertH – 2019-06-23T13:20:26.547final edit: All done now, I managed to combine your scripts and also it now returns the correct result. Thanks again. – RobertH – 2019-06-23T13:49:01.407