I am working on a little script to breakdown the data inside coinbase transactions. This is largely to improve my understanding of legacy and SegWit transactions (Given coinbase transactions have less data than for example a multisig TX, it is easier for me to work through).
One thing I've noticed about these transactions is differences in the output scripts. The Bitcoin RPC API works pretty well in decoding them, though I would like to know how to do it without an external tool. I am aware that there are different types such as P2PKH, P2SH, and P2PK. However, what I do not know is how to differentiate them only given the raw hexadecimal representation.
For example this transaction has two output scripts:
The RPC API tells me the first one has the type
pubkeyhash with a P2SH value of
The second output script appears to be random data which cannot be decoded. (I've also seen many coinbase transactions have one readable output and one or more output that cannot be decoded).
Another example, The genesis block coinbase transaction decoded by the RPC API has the type
pubkey with this script:
Question: How can I take this output script and determine the type of transaction and the assembly (OP script code) of it without external APIs?