What redeem script is used in bitcoin core wallet when generate the address?

1

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?

Kris Roofe

Posted 2018-04-08T05:42:11.307

Reputation: 135

Answers

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.

MeshCollider

Posted 2018-04-08T05:42:11.307

Reputation: 8 735

I use bitcoin core 0.16.0 the latest version. But when I use getaddressinfo I got "Method not found"Kris Roofe 2018-04-08T07:06:04.743

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: https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address

MeshCollider 2018-04-08T07:18:49.790

1Use 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 2018-04-08T07:21:11.150

@AndrewChow does validateaddress output the script? I wasn't sure if it did or if that was new functionalityMeshCollider 2018-04-08T08:18:07.220

@MeshCollider It does. The RPC was just split up in two in master, but no new functionality was added.Pieter Wuille 2018-04-08T12:51:35.847

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

JBaczuk

Posted 2018-04-08T05:42:11.307

Reputation: 6 172