since the topic is about creating segwit wallet, l want to ask something about redeem script
If I generated addresses with iancoleman tools, how to get redeem script of each P2SH address?
because I will be needing it to retrieve utxo of 3xx address for creating transaction (with coinb.in)
You can read how P2SH-P2WPKH addresses and redeemscripts are generated here:
https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-addressTo create a P2SH-P2WPKH address:
- Calculate the RIPEMD160 of the SHA256 of a public key (keyhash). Despite the keyhash formula is same as P2PKH, reuse of keyhash should be avoided for better privacy and prevention of accidental use of uncompressed key
- The P2SH redeemScript is always 22 bytes. It starts with a OP_0, followed by a canonical push of the keyhash (i.e. 0x0014{20-byte keyhash})
- Same as any other P2SH, the scriptPubKey is OP_HASH160 hash160(redeemScript) OP_EQUAL, and the address is the corresponding P2SH address with prefix 3.
Basically:
KeyHash = RIPEMD160( SHA256( Pubkey generated by IanColeman Tools ))
RedeemScript = 0014 + KeyHash
So, if your pubkey was: 03178c6ef588f5e8d595c1e9d1a0317dac1ec3e2c27d4d663a7ad72f285205790e
SHA256(PubKey) = D33ABE68F4B25D7E26F865872685D333CDAA96503B209D547A612FCF7060539E
RIPEMD160(SHA256) = 0BA27164080E9696D48F35F91CB26BECCAC23B4B
RedeemScript = 00140BA27164080E9696D48F35F91CB26BECCAC23B4B
IMPORTANT NOTE: Be careful if you're using "online" SHA-256 calculators... if you just copy/paste your public key into a lot of these online hash calculators, it WON'T give you the correct answer, as it is treating your pubkey as a string, rather than Hex Bytes... I suggest using:
http://gobittest.appspot.com/AddressPaste your pubkey into "1 - Public ECDSA Key", click "send"... your KeyHash will be in "3 - RIPEMD-160 Hash of 2"
and another question (unrelated to previous one), if I can create the raw tx manually in the human readable format
can I use non-synced bitcoin core to sign that raw tx? or it needs the blockchain to verify the tx?
I will then broadcast/push the signed transaction to the network thru bc.info or btc.com
I believe you can create and sign it without being synced... you just need to pass all the appropriate transaction info into the command