0

I'm using bitcoin-cli and I need to get the public key of one of my SegWit addresses. My first attempt was to use 'validateaddress' command and take the 'scriptPubKey' field but that doesn't seem to be the public key of the address. Any ideas?

1 Answer 1

1

Because a "segwit address" starting with a 3 is actually a specific type of P2SH, the scriptPubKey will just be a normal P2SH scriptPubKey, which doesn't reveal anything about the script itself (only a hash of the script). You need the redeem script, which will be a null byte followed by a push of the public key hash. From what I can recall, the script is output in the hex field of the validateaddress result.

Again, the public key hash doesn't actually reveal the public key, so once you have that there will probably be an extra step required, perhaps conversion of the public key hash into an address starting with a 1 and then validateaddress on that.

It is unfortunate that the support for segwit addresses is not great in version 0.15.x, it'll be much better in 0.16 when Peter Wuille's segwit wallet PR is merged

1
  • 1
    This did the trick! I took the "hex" field from "validateaddress" and decoded it using command "decodescript". There in the "asm" field I found the public key hash (the second string). Then using blockchain.info I searched for that hash and I landed in the legacy address behind the SegWit address. Using "validateaddress" one more time I found the public key in the "pubkey" field. Thanks a lot!
    – Paul
    Commented Jan 3, 2018 at 18:57

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.