Sending a Bitcoin Transaction Using Bitcoins

Can someone explain how can I send a bitcoin transaction using bitcoins? I set up two wallets using bitcoins.

I want to send 100,000 satoshi from here: 1G4iprWu7Q8tNbQLA8UBM2GearcnzwFrxM

here: 1HsrKvboax8J3X1sgsRdWybEwnUNWsDw4Y

If necessary, here is the last transaction for 1G4iprWu7Q8tNbQLA8UBM2GearcnzwFrxM

The code I use is on bitcoinjs.org:

var tx = new bitcoin.TransactionBuilder() // Add the input (who is paying): // [previous transaction hash, index of the output to use] var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31' tx.addInput(txId, 0) // Add the output (who to pay to): // [payee address, amount in satoshis] tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000) // Initialize a private key using WIF var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy' var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF) // Sign the first input with the new key tx.sign(0, keyPair) // Print transaction serialized as hex console.log(tx.build().toHex()) // => 0100000001313eb630b128102b60241ca895f1d0ffca21 ... // You could now push the transaction onto the Bitcoin network manually // (see https://blockchain.info/pushtx) 

Now I assume that var txId is the transaction id from the last transaction here

Is `tx.addInput` where I put the board? If so 100 is enough?

tx.addOutput is obvs, so I'm fine with that!

Is var privateKeyWIF* where I put the private key from the send address?

I do not know what to do var keyPair and tx.sign !

Anyone who can help me tell me where the details should go will be very grateful! For this example, pretend that my private key for the sender address is 5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF .

Greetings

+5
source share
1 answer

Wif

First understand that with the format .

Inputs

From github we have:

Transaction.prototype.addInput = function (hash, index, sequence, scriptSig)

so you need to pass the transaction hash and index (the output of which will be your input), you should check what bitcoin tx is

key pair

It is not verified that perhaps keyPair is your Pk and pk.

signatures

Please also check that since I did not, but logically tx.sign(index, keyPair) must sign tx (SIGHASH_ALL) to enter the index with the private key in keyPair . If you have more than one entry, you must provide a signature for each. Take a look at bitcoin mastering

0
source

Source: https://habr.com/ru/post/1262899/


All Articles