How do you output segwit bech32 (bc1...) / P2SH (3...) addresses from a bitcoin private key?

0

1

I have a bitcoin private key and know that it can output a segwit addresses of bech32 bc1... and p2sh 3... formats. How can this be done easily?

Patoshi パトシ

Posted 2018-03-28T14:21:38.320

Reputation: 8 911

Answers

0

Load up electrum 3.1.1+ and enable the "console" and in the console do the following to output the addresses you need by providing your private key:

bech32 format bc1...:

bitcoin.address_from_private_key("p2wpkh:5Kkzs8XrJNAmf9......")

p2sh format 3...:

bitcoin.address_from_private_key("p2wpkh-p2sh:5Kkzs8XrJNAmf9VQDFeG......")

you just need to prefix your private key with p2wpkh or p2wpkh-p2sh to get one of them.

Patoshi パトシ

Posted 2018-03-28T14:21:38.320

Reputation: 8 911

Keep in mind that this function requires the WIF encoding of the private key as an input.Mike D 2018-03-28T15:58:43.563

how do you get the WIF encoding?Patoshi パトシ 2018-03-28T16:27:38.787

I dont know about electrum but I have made a python library that can do what you want. PrivateKey.from_hex('yourkeyhere').to_public().to_address('P2WPKH')

Mike D 2018-03-28T16:39:59.123