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!
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 Thanks for the answer. I understand it better now and I was able to create a transaction.
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);
......... txid is correct... lol
Most helpful comment
@clarkmoody Thanks for the answer. I understand it better now and I was able to create a transaction.