Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: zkquality on October 17, 2021, 03:40:43 AM



Title: The TX id that we need to create a transaction
Post by: zkquality on October 17, 2021, 03:40:43 AM
I have no idea if it was asked before. when spending from paper wallet, we need to create a watch-only wallet first, then electrum gets some data from bitcoin network and save it into a file, then we sign that file with the real-wallet.

so basically while seeing the bitcoinjs documents, to create a transaction we need a "TXID" of a pervious transaction. so if I have a wallet with multiple transactions and all of them are deposits, then which one do we need its TXID now? can anybody please explain?

also, why do we need a watch only wallet first before signing transaction? i mean what kind of data does electrum get from the address and the network.

tnx in advance


Title: Re: The TX id that we need to create a transaction
Post by: ranochigo on October 17, 2021, 04:31:14 AM
You select the inputs that you'd like to spend in the transaction. Get the TXID and the output index of it for the transaction, for which the output index is the order for which your output is in within that specific transaction.

Electrum obtains the unspent transaction output and displays it to the user in the GUI for them to choose and construct an unsigned transaction for it to be signed, that is the purpose of a watch-only wallet.


Title: Re: The TX id that we need to create a transaction
Post by: zkquality on October 17, 2021, 04:54:27 AM
You select the inputs that you'd like to spend in the transaction. Get the TXID and the output index of it for the transaction, for which the output index is the order for which your output is in within that specific transaction.

Electrum obtains the unspent transaction output and displays it to the user in the GUI for them to choose and construct an unsigned transaction for it to be signed, that is the purpose of a watch-only wallet.

Did you mean I cannot spend multiple transactions at once?

Can you please explain more? So If the wallet has 1 btc that was received in a multiple unspent transactions. e.g. 10x 0.1 BTC deposited. Then I want to spend them all, which transaction should I use its TXID now?

Thanks.


Title: Re: The TX id that we need to create a transaction
Post by: pooya87 on October 17, 2021, 04:55:05 AM
so basically while seeing the bitcoinjs documents, to create a transaction we need a "TXID" of a pervious transaction. so if I have a wallet with multiple transactions and all of them are deposits, then which one do we need its TXID now? can anybody please explain?
You don't need TXID you need UTXO (Unspent Transaction Output) which contains [received] transaction hash, index of the output in that transaction, amount of the output in satoshis and finally the pubkey script (that should correspond with the address you are spending from).
You get a list of them that belong to your address and spend as many of them as you want granted you don't violate any standard rules (ie. don't end up with a huge tx).

Quote
also, why do we need a watch only wallet first before signing transaction?
You don't need a watch only wallet first, it is an option to maximize security.

Quote
when spending from paper wallet, we need to create a watch-only wallet first, then electrum gets some data from bitcoin network and save it into a file, then we sign that file with the real-wallet.
Electrum gets a list of UTXOs for your address and then it creates an unsigned transaction that has everything expect signatures set (such as inputs and outputs) then puts it in a file that you can transfer to cold storage for signing. The cold storage reads the file and signs the transaction (not the file) then you can transfer the signed transaction in that file to the online watch only wallet to broadcast.


Title: Re: The TX id that we need to create a transaction
Post by: zkquality on October 17, 2021, 04:56:54 AM
so basically while seeing the bitcoinjs documents, to create a transaction we need a "TXID" of a pervious transaction. so if I have a wallet with multiple transactions and all of them are deposits, then which one do we need its TXID now? can anybody please explain?
You don't need TXID you need UTXO (Unspent Transaction Output) which contains [received] transaction hash, index of the output in that transaction, amount of the output in satoshis and finally the pubkey script (that should correspond with the address you are spending from).
You get a list of them that belong to your address and spend as many of them as you want granted you don't violate any standard rules (ie. don't end up with a huge tx).

Quote
also, why do we need a watch only wallet first before signing transaction?
You don't need a watch only wallet first, it is an option to maximize security.

Quote
when spending from paper wallet, we need to create a watch-only wallet first, then electrum gets some data from bitcoin network and save it into a file, then we sign that file with the real-wallet.
Electrum gets a list of UTXOs for your address and then it creates an unsigned transaction that has everything expect signatures set (such as inputs and outputs) then puts it in a file that you can transfer to cold storage for signing. The cold storage reads the file and signs the transaction (not the file) then you can transfer the signed transaction in that file to the online watch only wallet to broadcast.

What to do with case they are multiple unspent ones?


Title: Re: The TX id that we need to create a transaction
Post by: ranochigo on October 17, 2021, 04:57:16 AM
Did you mean I cannot spend multiple transactions at once?
You're never spending multiple transactions, you are spending multiple transaction outputs. It is possible and easy to do so. Just reference all of them in the transaction that you want.
Can you please explain more? So If the wallet has 1 btc that was received in a multiple unspent transactions. e.g. 10x 0.1 BTC deposited. Then I want to spend them all, which transaction should I use its TXID now?
All of them. The transaction needs to reference all of their TXIDs and their corresponding indexes.


Title: Re: The TX id that we need to create a transaction
Post by: zkquality on October 17, 2021, 05:15:44 AM
You don't need a watch only wallet first, it is an option to maximize security.

Does that mean with just the - private key - I can create a raw transaction without getting any data from the Bitcoin network?


Title: Re: The TX id that we need to create a transaction
Post by: pooya87 on October 17, 2021, 05:20:11 AM
What to do with case they are multiple unspent ones?
I already said it, you get a list of UTXOs and you can spend as many of them as you want.
Each bitcoin transaction has an array of inputs and an array of outputs that have to have at least one item in them (one input and one output) but you can create a transaction with for example 10 inputs and 4 outputs.

You don't need a watch only wallet first, it is an option to maximize security.
Does that mean with just the - private key - I can create a raw transaction without getting any data from the Bitcoin network?
No.
A watch-only wallet is a wallet that does NOT contain any private keys. It is created using the addresses (or technically could be with public keys too). It provides security since your private keys remain offline.
But you still need to construct a transaction knowing the UTXOs you can spend and you can only find them by knowing the address and searching the bitcoin blockchain.


Title: Re: The TX id that we need to create a transaction
Post by: zkquality on October 17, 2021, 05:51:44 AM
I already said it, you get a list of UTXOs and you can spend as many of them as you want.
Each bitcoin transaction has an array of inputs and an array of outputs that have to have at least one item in them (one input and one output) but you can create a transaction with for example 10 inputs and 4 outputs.

Oh, it seems that I know nothing at all. I thought transaction inputs are addresses like they appear on block explorers. Anyway thank you guys I'm investigating this again.


Title: Re: The TX id that we need to create a transaction
Post by: o_e_l_e_o on October 17, 2021, 09:33:55 AM
I thought transaction inputs are addresses like they appear on block explorers.
This is just done to make it easier for humans to navigate, since we are generally more interested in the total balance of bitcoin at each address as opposed to the balance of each individual UTXO. At a protocol level, the inputs to each transaction are selected based on the outputs of previous transactions.

The block explorer blockstream.info will instead show each input as "TXID:Index", rather than as coming from a specific address. For example, if we take this transaction: https://blockstream.info/tx/435656e0e95952ff44df53906625be446451fd6fb3f1a051c14e491bd917043d. The first input to that transaction is the eighth output (7) of the transaction with hash 3227e..., the next input is the 34th output (33) of the transaction with hash 46d7e..., and the last input is the first output (0) of the transaction with hash c6277....

You also might find this a useful resource: https://learnmeabitcoin.com/technical/transaction-data