there are two type of segwit as P2SH starting with 3 and Native SegWit (bech32) starting with bc1, but don't know which of the two segwit one, is better and is compatible to transfer and receive from a legacy one?
Generally speaking the "bc1" native SegWit address is better. It's completely redesigned comparing to the classical/legacy Base58 encoding ...
The number of inputs and outputs affect transaction size (bytes). The more inputs/outpus you have, the larger is the transaction size. Segwit addresses reduces transaction size.
So the best is to always consolidate your inputs when the fees are low, so that we the network is congested you can make a transaction with a single input and two outputs (one for ...
Format for 1 input 2 outputs (1 to receiver, 1 change to owner). Normal non-seg transaction
P2SH 73 bytes(input) 32x2 (output)
P2PKH about the same as P2SH
To reduce fees reduce
a) no of inputs.
b) Use exact match (with no change output) if possible.
c) when fee is low, use more inputs or consolidate your input to fewer UTXO.(reduction of input ...
I thought vbytes were equal to weight units divided by 4
It is *, but rounded up to the next integer, so the implementation in bitcoind is :
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
return (std::max(nWeight, nSigOpCost * bytes_per_sigop) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
Here "witnessScript" is RedeemScript, right?
what is meaning of 'CODESEPARATOR' here?
CODESEPARATOR is an (interesting *) OP code which allows to customize the behaviour of the CHECKSIG OP code. It allows to section the script code for a signature to commit to only part of it.
BIP143 slightly changed its behaviour for SegWit scripts.
why need ...
From bitcoin-cli help decodescript:
"asm":"asm", (string) Script public key
"type":"type", (string) The output type (e.g. nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_unknown)
"reqSigs": n, (numeric) The required signatures
"addresses": [ (json ...
Because the address you are using is a P2SH-P2WPKH address as you mention (sh (wpkh ())), you get the output
It is talking only about the top level (P2SH), because it is a P2SH address, regardless of what the script "inside" it encodes. It doesn't "see" the underlying P2WPKH when you call validateaddress. The ...
(SCRIPTCODE is P2PKH script: OP_DUP OP_HASH160 OP_EQUAL OP_CHECKSIG
Your script code is missing the OP_CheckSig that is 0x88 so consequently your final hash (hashPreimage) is wrong and the signature is produced from an entirely different hash digest hence is invalid.