Normally when you spend an input, you reveal your public key and signature so that ECVERIFY can be done.

I look at segwit raw transactions and cannot find the public key inside them, where do they go?

Example: https://www.blockchain.com/btc/tx/3179d18d6f36fa77b88909496535485d8188d96b79d295843789a9e0ff6c3e6a

Is there a way to reliably retrieve the pubkey and it's position in the raw transaction?

1 Answer 1


It's in the witness right after the signature.

ScriptSig: PUSHDATA(22)[00144b9d2d3dd1174ad656754a0c664e7a129b131f3b]
Witness:     0247304402201cf8db0c4afc164970ec4397327fe9b1dd9b7ff4a9093f94e554d624b5ffdcb702202848072c17f2bcce16b8d3d7cb2efdad87bc6c942b79f44b79f1c52f817d81ea012102384052a5ecde83bf8ee7ed77f378edb58aa65de22c4e91af87eee68015b9d509



Is there a way to reliably retrieve the pubkey and it's position in the raw transaction?

You have to parse the witness.

02 : 2 items to follow

47 : 0x47 = 71 bytes (signature)

304402201cf8db0c4afc164970ec4397327fe9b1dd9b7ff4a9093f94e554d624b5ffdcb702202848072c17f2bcce16b8d3d7cb2efdad87bc6c942b79f44b79f1c52f817d81ea01 : the actual signature (last byte is the sighash code)

21 : 0x21 = 33 bytes (the pubkey)

02384052a5ecde83bf8ee7ed77f378edb58aa65de22c4e91af87eee68015b9d509 : the actual pubkey

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.