I'm trying to get the addresses from the ScriptPubKeys in each transaction (where possible). So far, I know of two patterns of ScriptPubKey where an address can be found:

1. Pay-To-Pubkey

04e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93 OP_CHECKSIG

In this locking script, the code before OP_CHECKSIG is a public key, so that can be converted in to an address.

2. Pay-To-Pubkey-Hash

OP_DUP OP_HASH160 3d37cde30fdfcf29b2996a7ceefd220ba32c9f4b OP_EQUALVERIFY OP_CHECKSIG

In this one, the code after OP_HASH160 (and before the next OP code) is the hash160 of a public key, so that can be converted to an address also.


Are there any other patterns of ScriptPubKey where addresses can be found?

Or in other words, will I be able to capture every address by working on all non-opcodes before OP_CHECKSIG, and all non-opcodes after OP_HASH160?

2 Answers 2


Technically, pay-to-pubkey doesn't have an address type. You can derive an address as if it were a pay-to-pubkeyhash scriptPubKey, but there is a subtle difference.

The other type you are forgetting is a pay-to-scripthash type. It's of the format

OP_HASH160 <Hash160(redeemScript)> OP_EQUAL

Then, you get a p2sh adddress by prepending the version byte and appending the checksum to <Hash160(redeemScript)>



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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