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 3EstC3Hhe8zvNGP73oX9oDvo36sNCygjJi

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?

Thank you!

  • As I was writing this I stumbled upon this image which implies that the scriptPubKeys follow a standardized format, can someone confirm it is accurate? Thanks again! – KappaDev Sep 9 '18 at 23:34

thx for linking one of my older pics from 2016 :-) meanwhile things had changed, especially the multisig was not clear enough. I attach an updated version here. I didn't have the time to put newest SegWit related things into the pic though... Still happy to see other opinions ...

output script

  • Thanks man! I ended up figuring out most of the information I needed once I reviewed your picture. One other question I figured I'd ask. I know with the adoption of segregated witness there has been some degree of backwards compatibility with P2SH. Though, I have also heard people mention P2SH-P2WSH, P2WSH, P2WPKH, and P2SH-P2WPKH. Would you happen to know what differences there are in these versions, if any? Or perhaps a thread that might share the details? Regardless, thanks for this! PS: I'd love to upvote this too, but I don't have enough reputation yet :( – KappaDev Sep 10 '18 at 17:14
  • I haven't seen any "prepared" stuff for easy usage, so my reference is currently here: en.bitcoinwiki.org/wiki/Segregated_Witness - with the links at the bottom to BIPs and the Wallet Development Guide. – pebwindkraft Sep 10 '18 at 18:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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