My goal is to create a transaction. For that I need to know the following things:
- The private key signing the transaction.
- Who can spend the bitcoins that I'm sending.
- Valid UTXOs that the sender can spend.
When creating the outputs, I need to add the scriptPubKey, which in my understanding is a script that specifies how the bitcoin can be spent. I know how to get the scritPubKey from and address (actually, I mean there is a way to do it if using Peter Todd's python-bitcoinlib codebase here. But, given a public key hash, I don't really understand how to do it.
Ex: Given this hash of a public key: mz64DQXTMiSYwZFQqaggUrMG82MA4TW2wx, how to get the scriptPubKey from it?
What I expect in term of answer (not exclusively):
- Clarification on what is the difference between these things: public key hash, scriptPubKey, addresses.
- Implementable steps to get the scriptPubKey.
- I realise that using this hash of the public key, I can send transactions directly to it and treat it as an address and some explorer calls it address, how is that possible?
- Resource recommendation to go further in the understanding.
What is clear to me: From this site, I understand that the hash comes from hashing the public key with hash160 and adding checksum 4 bytes. I believe by reverting this process, I could get the public key and generate an address and get the scriptPubKey from the address, but I believe there can be better way to do it.