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?

up vote 2 down vote accepted

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 2 hours ago
  • 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 2 hours ago
  • 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 2 hours ago
  • @AndrewChow does validateaddress output the script? I wasn't sure if it did or if that was new functionality – MeshCollider 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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