1

I'm trying to generate the address 38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa in my bitcoin core wallet with code.

First, I dump the private key from the address, then I calculate the address from the private key. As the address is start form m, which is of P2SH bitcoin address type. And the P2SH address is constructed as

base58-encode: [one-byte version][20-byte hash][4-byte checksum]

Here I don't know what the script used to calculate the [20-byte hash] in the bitcoin core wallet?

2

You can use the getaddressinfo RPC command in the latest version of bitcoin core to get the hex encoded script for that address. But note that because you were able to get a private key, I assume this is a P2SH wrapped segwit address, which means the script is just an OP_0 opcode followed by the hash160 of the public key corresponding to that private key.

  • I use bitcoin core 0.16.0 the latest version. But when I use getaddressinfo I got "Method not found" – Kris Roofe Apr 8 '18 at 7:06
  • 1
    Oh apologies, I thought it had made it into 0.16, it looks like its still only on the master dev branch. In that case you might have to create the script yourself using the OP_0 + hash160 approach I mentioned, see here for more info: bitcoincore.org/en/segwit_wallet_dev/… – MeshCollider Apr 8 '18 at 7:18
  • 1
    Use validateaddress instead (the parts of validateaddress that give address information are moved to a new getaddressinfo command for the next major version, 0.17). – Andrew Chow Apr 8 '18 at 7:21
  • @AndrewChow does validateaddress output the script? I wasn't sure if it did or if that was new functionality – MeshCollider Apr 8 '18 at 8:18
  • @MeshCollider It does. The RPC was just split up in two in master, but no new functionality was added. – Pieter Wuille Apr 8 '18 at 12:51
0

(For additional detail):

It is a P2SH-P2WPKH (Pay to witness public key hash wrapped in a pay to script hash). To create this address for mainnet:

  1. Create Witness PKH:

PKH = OP_0 0x14 RIPEMD160(SHA256(compressed public key))
0x14 is number of bytes

  1. Create P2SH:

BASE58CHECK(0x05 PKH)
0x05 is the mainnet P2SH prefix

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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