0

I'm using bitcoin core 0.16.0 on regtest and call getnewaddress
I'm getting "2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1"
As I call validateaddress "2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1" I get:
{ "isvalid": true, "address": "2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1", "scriptPubKey": "a9147cef86e3cf39b81f5263375b798536f19d4e8d0687", "ismine": true, "iswatchonly": false, "isscript": true, "iswitness": false, "script": "witness_v0_keyhash", "hex": "00147568d37152e5b720780b2e4d2346db97b2af5d8f", "pubkey": "0211ea7f9c2f4aba987926365ecbe009788d6ca905231f28828ff301d261cfc06d", "embedded": { "isscript": false, "iswitness": true, "witness_version": 0, "witness_program": "7568d37152e5b720780b2e4d2346db97b2af5d8f", "pubkey": "0211ea7f9c2f4aba987926365ecbe009788d6ca905231f28828ff301d261cfc06d", "address": "bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga", "scriptPubKey": "00147568d37152e5b720780b2e4d2346db97b2af5d8f" }, "addresses": [ "bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga" ], "account": "", "timestamp": 1517310214, "hdkeypath": "m/0'/0'/37'", "hdmasterkeyid": "c975977fb41bc2613d6cda5f10b917a2954893ad" }

What is the segwit address ? is it the one I got from getnewaddress or "bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga" inside the "embedded" section with "iswitness" : true ?

So to check this issue I've send to both addresses 2 btc on regtest and decoded the rawtransaction, for 2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1 tx is:

{ "txid": "03a9d0e354d2ab25a5b14d0aa9a7651e7209a61596cd81886a501a6968cfb721", "hash": "668ca307cf165b2e5658de7278545ddaad3e071147d41293f60471442a3eddd9", "version": 2, "size": 247, "vsize": 166, "locktime": 115, "vin": [ { "txid": "cea9f59c19c8dbaf1e2cb253a2980228a45c9658b8b7e48a87288a1d269867f9", "vout": 0, "scriptSig": { "asm": "00142f6c397ad231f08de05da5d0aee634dd5974f75a", "hex": "1600142f6c397ad231f08de05da5d0aee634dd5974f75a" }, "txinwitness": [ "304402201d063a846bc7f8504399d47649e7749e4c6c68070cb2840fb72d1c3f2cc717f302202b0314aea962da5aa056e33e71315ad9f0e4e0501dacc800fee82b70c870e79601", "03ecef34be2e1f0a1dc7ec43fa2248cf0d06d85be13c8220aec6bda0d0405c19c2" ], "sequence": 4294967293 } ], "vout": [ { "value": 4.00029480, "n": 0, "scriptPubKey": { "asm": "OP_HASH160 bf181b015a2022e0d2d63c2af8793c0addb117ce OP_EQUAL", "hex": "a914bf181b015a2022e0d2d63c2af8793c0addb117ce87", "reqSigs": 1, "type": "scripthash", "addresses": [ "2NAfdvoVHL3XWtiyB4ULkB7sST71ZafEVXg" ] } }, { "value": 1.00000000, "n": 1, "scriptPubKey": { "asm": "OP_HASH160 7cef86e3cf39b81f5263375b798536f19d4e8d06 OP_EQUAL", "hex": "a9147cef86e3cf39b81f5263375b798536f19d4e8d0687", "reqSigs": 1, "type": "scripthash", "addresses": [ "2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1" ] } } ] }

and for bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga tx is:
{ "txid": "ed857e7318cca006a7f1f975c65742a1cdddf36e46b6f37b958e402c99da47f5", "hash": "ed40689ddf66c293ec9cc2c10fb7bb732c7b4e1e3d48c6ae0cd3644a4cad6b27", "version": 2, "size": 222, "vsize": 141, "locktime": 115, "vin": [ { "txid": "982bb35cc6057afbe92c75527b6c62b4ec855f4155042ef0fadbf784e1b60267", "vout": 0, "scriptSig": { "asm": "", "hex": "" }, "txinwitness": [ "3044022073995927c65c6dade5b8e141fb5c16095b233e163ce5fa28cd18eeb73f68f45f0220749ec988d670cb04b6aec57c0f43bf8ba67331849ce76c70e92a2c7605bb26bd01", "0379cc68acccb4442006844530052f7b5fbfe84e5ebb46a1f509f9fc474be4715c" ], "sequence": 4294967293 } ], "vout": [ { "value": 29.00024460, "n": 0, "scriptPubKey": { "asm": "0 acf33e42618956e6df4e1265d7c44500d0fa3c1e", "hex": "0014acf33e42618956e6df4e1265d7c44500d0fa3c1e", "reqSigs": 1, "type": "witness_v0_keyhash", "addresses": [ "bcrt1q4nenusnp39twdh6wzfja03z9qrg050q76nct4r" ] } }, { "value": 1.00000000, "n": 1, "scriptPubKey": { "asm": "0 7568d37152e5b720780b2e4d2346db97b2af5d8f", "hex": "00147568d37152e5b720780b2e4d2346db97b2af5d8f", "reqSigs": 1, "type": "witness_v0_keyhash", "addresses": [ "bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga" ] } } ] }
So my understanding is that "bcrt1qw45dxu2jukmjq7qt9exjx3kmj7e27hv0umayga" is the SegWit address cause I see at vout that the tx uses "witness_v0_keyhash" to sign the 1 btc . am I correct ? if so , why do I need to call validateaddress on the legacy address to view it's SegWit address ? What am i doing wrong ?

3

The address you need to sent to is 2N4dpih8KAdfJyXn2vhWixUwmYJ6DBfeRM1, as that is the output of getnewaddress.

That's a P2SH-P2WPKH address, which became the default in 0.16. It is not a legacy address, but a P2SH-embedded segwit address.

If you want a P2WPKH (native, bech32) address, you should tell getnewaddress that is what you want, by calling getnewaddress "" "bech32". Alternatively, you can tell bitcoind that you always want by putting addresstype=bech32 in bitcoin.conf.

Never try to convert one address type into another yourself. validateaddress is giving you information about the address you passed in. bitcoind does not expect payments to anything but the address that getnewaddress gave you.

  • Will i need to use bech32 at some point in the future adoption of segwit ? – Haddar Macdasi Apr 4 '18 at 19:39
  • If you like. No reason why you have to. It's just a bit cheaper for you if you do (as spending transactions will have lower weight). – Pieter Wuille Apr 4 '18 at 20:32
  • @PieterWuille Did you mean using bech32 addresses we pay less tx fees? – CryptoMiningPoolSetupYiimp Apr 5 '18 at 8:56
  • Yes, if you receive coins using bech32 addresses (as in: you're giving bech32 addresses to others who pay you), it will (over time) become cheaper for you to send coins. The difference for typical transactions is around 20%. – Pieter Wuille Apr 5 '18 at 12:00

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.