bitcoinjs-lib icon indicating copy to clipboard operation
bitcoinjs-lib copied to clipboard

Question creating a Transaction

Open cbedoya opened this issue 9 years ago • 4 comments

Hello

I am trying to understand how a transaction works and I am having bad time figuring out one of the parameters. In your example you have this:

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31'
tx.addInput(txId, 0)

So where do that hash come from? My first guess, according to the comment is that I need to look into the last received transaction into the from address, then get the tx hash and add it as an input. Is that accurate? Also, should I always use the index 0 or in what escenarios do I need to use a different index?

Another question is, lets say in my address I have 1 btc, then I receive 0.5 btc, and I want to send 1.2 btc to another address. Is it ok to just get the hash from the received 0.5btc or what other info do I need?

And one last question, using the same example, after receiving the 0.5btc, I want to send 2 times, should I use the same hash that came from the received 0.5 or in the first send action, I get the hash then use it on a 2nd transaction?

I would appreciate any help on this.

Thanks!

cbedoya avatar Jul 18 '17 18:07 cbedoya

I would take a look at the Bitcoin Developer Guide to read a little more about transaction construction.

Also, get some Testnet coins to perform these sorts of tests :smile:

clarkmoody avatar Jul 18 '17 19:07 clarkmoody

@clarkmoody Thanks for the answer. I understand it better now and I was able to create a transaction.

cbedoya avatar Jul 20 '17 00:07 cbedoya

Hi, I am creating a transaction for mobile. Please let me know how can I get taxid? Should I use: https://api.smartbit.com.au/v1/blockchain/address/1BvvRfz4XnxSWJ524TusetYKrtZnAbgV3r/unspent But It returns array, which one is correct?

 const txId = ''; //
 tx.addInput(txId, 0);

VishalKumar2016 avatar Mar 08 '18 13:03 VishalKumar2016

......... txid is correct... lol

dabura667 avatar Mar 08 '18 14:03 dabura667