Closed TorgaW closed 9 months ago
Finally, prepare for signing:
Is the amount you are setting for "wally_tx_get_btc_signature_hash" 25000? If your current UTXO's amount is 30000+(tx fee amount), you should specify 30000+(tx fee amount).
Broadcast
~Also, the transaction fee is not set to transaction output in the first place.~ ~I think cannot broadcast this transaction in this state.~ Sorry, I mistook it for Elements. Don't worry about it here.
byte sig_input_script[26]; sig_input_script[0] = 0x19;
0x19
is script size. please remove from sig_input_script.
byte sig_input_script[25];
sig_input_script[0] = 0x76;
sig_input_script[1] = 0xA9;
sig_input_script[2] = 0x14;
//copy pubKeyHash
memcpy(&sig_input_script[3], w0.receive_addresses[0].as_bytes + 2, 20);
sig_input_script[23] = 0x88;
sig_input_script[24] = 0xAC;
should use wally_scriptpubkey_p2pkh_from_bytes
.
Got it! Broadcasted successfully!
There were 2 problems:
1) You was right with satoshi amount problem! In UTXO I have 35082 value, but put in function only 20000... stupid mistake!
2) Script problem: 0x19
is redundant, a little bit confused why in a moment, but now see a comment The (unprefixed) scriptCode, so got it!
Many thanks to you! I really like wally library, the best bitcoin library for C/C++!
Thanks @ko-matsu !
I'm trying to create a bitcoin wallet for educational purpose and want to implement Segwit support.\ Currently I'm working with Testnet.\ I have done already wallet private key generation with bip32_key_from_seed() function:
After private key generation I'm creating SegWit address:
For example we have this address: tb1qsrfp2j0qgtcv767lu5rzxjgw3lz444jet00mu9\ After that I'm generating 2 more addresses: change and recepient\ \ Change: tb1qh5vxl5xhzc2vqhs7kag8hugzcw7w86kvc855ar\ Recepient: tb1qep9mf5377l2xxv8lle38hfshjjr6xxnhvl0gra\ \ I have sent some testnet bitcoins to tb1qsrfp2j0qgtcv767lu5rzxjgw3lz444jet00mu9 and got UTXO:
Creating a new transaction
I'm starting with creation of wally_tx_input struct:
Then two outputs:
After inputs and outputs creation I'm creating wally_tx struct and fill with inputs and outputs:
Finally, prepare for signing:
Sign and set witness stack:
After signing I'm converting *new_tx to bytes:
And the result is:
Broadcast
I'm using blockcypher webpage to broadcast raw transaction in testnet network, but got an error:
I have found official BIP143 wiki in bitcoin repo on github, but it didn't help :(\ I really want to know at wich point I made a mistake.