I am new to crypto world as a developer.
I want to receive online payments with bitcoin.
I see that there are many functions available for creating address at disposal, but which one do you choose and how are they different?
It is a noob question, but which address type is the most standard?
It would be really great if there is a wiki explaining the differences.
Thank you in advance.
If you just want to generate a standard bitcoin address you can do:
var keyPair = bitcoin.ECPair.makeRandom()
var address = keyPair.getAddress()
I'd start looking at SegWit addresses though, which should be cheaper to send coins to:
var keyPair = bitcoin.ECPair.makeRandom()
var pubKey = keyPair.getPublicKeyBuffer()
var scriptPubKey = bitcoin.script.witnessPubKeyHash.output.encode(bitcoin.crypto.hash160(pubKey))
var address = bitcoin.address.fromOutputScript(scriptPubKey)
I got the code above from the examples in the test code.
@dcousens Does this look about right?
@ralphtheninja spot on.
The latter example will hopefully be simpler in 4.0.0.
@ralphtheninja Thank you very much! Why would anyone wants to create standard if SegWit is cheaper?
@joonhocho compatability. Old software/hardware. Etc.
@dcousens I see. So if I create SegWit then there's a chance that someone may not be able to send to the address. What happens if someone with standard address tries to send their coin to my SegWit address? Will it bounce or be lost?
@joonhocho yes, but you shouldn't hold back because others haven't upgraded...
The alternative is wrapping the above in a P2SH address, but, that is lame and complicates your spending code.
I heard Coinbase is not supporting SegWit yet, does that mean Coinbase users cannot send me coins if I create SegWit address? If that is the case, then it should be pretty significant.
@joonhocho then your best bet is a P2SH address wrapping P2WPKH.
See the example here: https://github.com/bitcoinjs/bitcoinjs-lib/blob/8bd95bd49808c9eeba2b065ef6552c7a9d07963e/test/integration/addresses.js#L60-L69
@dcousens Thank you so much.
Most helpful comment
If you just want to generate a standard bitcoin address you can do:
I'd start looking at SegWit addresses though, which should be cheaper to send coins to:
I got the code above from the examples in the test code.
@dcousens Does this look about right?