Title: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: HoBzY on October 04, 2022, 06:01:17 PM https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format
https://developer.bitcoin.org/reference/transactions.html#outpoint-the-specific-part-of-a-specific-output How to get an outpoint in a transaction? I'm trying to parse the structure of an unprocessed transaction. How to get this c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704 hash? Code: 0100000055bd840a78798ad0da853f68974f3d183e2bd1db6a842c1feecf222a00000000ff104ccb05421ab93e63f8c3ce5c2c2e9dbb37de2764b3a3175c8166562cac7d51b96a49ffff001d283e9e70 Help me figure it out. Can you give an example of generating this hash? Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: NotATether on October 04, 2022, 08:10:11 PM The long string you posted starting with c997... is he transactions ID of the spent output. The 00000000 immediately following it indicates it was the first output of this transaction that has been spent (beware - this and other fields might stored in big-endian, so endian conversion might be necessary)
Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: HoBzY on October 04, 2022, 08:14:41 PM The long string you posted starting with c997... is he transactions ID of the spent output. The 00000000 immediately following it indicates it was the first output of this transaction that has been spent (beware - this and other fields might stored in big-endian, so endian conversion might be necessary) How does it look in code? well, creating such a hash Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: BitMaxz on October 04, 2022, 11:59:24 PM Are you talking about Raw/Hex transaction? Thats the link you provided above.
If you want to generate unsigned raw/hex transaction Electrum watch-only wallet have this option just import the public or Btc address that you own to Electrum wallet then make a transaction it should generate a raw/hex transaction. Or you can use this https://coinb.in/#newTransaction to generate unsigned raw/hex transaction. What exactly wallet did you generate this hash c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704? Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: pooya87 on October 05, 2022, 03:16:58 AM You have to first parse/deserialize the transaction, so you either have to read the first link you posted (raw-transaction-format) to learn how to do it or find a library that does this.
Then you'll have a transaction that has a list of inputs (tx_in), in each input you will have a transaction hash and an index. The combination of these two is the outpoint. That hash in each outpoint is the double SHA256 hash of the transaction that contains the output (or coins) you are spending. That index is the index of that output (or coin) inside the previous transaction's output (tx_out) list. Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: nc50lc on October 05, 2022, 03:18:49 AM How to get an outpoint in a transaction? Here's an example then:I'm trying to parse the structure of an unprocessed transaction. -snip- Help me figure it out. Can you give an example of generating this hash? Let's say you want to spend the first output of this transaction: blockstream.info/tx/4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 (https://blockstream.info/tx/4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306) The short version is, that's the TXID that should be used in your transaction input's outpoint. The long version is, you can get that by hashing (SHA256D) the to-be-spent RAW transaction; for SegWit, witness data should be omitted first. getrawtransaction 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306: Code: 02000000 Code: 0200000001edbc78c31ef4beb3f99727513772c95438ab938d0e9e012fb63c21d971d59eed1600000017160014bfe3f2baee0e4e0acb9a09564d85f95f64a08644fdffffff02a086010000000000225120c7da8b195d9e93cb321000adfd2c56ffe30969780cf4e09b782966e38d76761d70e1080000000000160014eee8c12b1093ef4780509809116f931b1fc6ea5adc8b0b00 SHA256: 06434a888fda769b0255deb79bc447555c60c28bfdbadfb9e6043b397e2eca4a Reverse byte order: 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 A few references:
Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: HoBzY on October 05, 2022, 07:32:44 AM How to get an outpoint in a transaction? Here's an example then:I'm trying to parse the structure of an unprocessed transaction. -snip- Help me figure it out. Can you give an example of generating this hash? Let's say you want to spend the first output of this transaction: blockstream.info/tx/4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 (https://blockstream.info/tx/4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306) The short version is, that's the TXID that should be used in your transaction input's outpoint. The long version is, you can get that by hashing (SHA256D) the to-be-spent RAW transaction; for SegWit, witness data should be omitted first. getrawtransaction 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306: Code: 02000000 Code: 0200000001edbc78c31ef4beb3f99727513772c95438ab938d0e9e012fb63c21d971d59eed1600000017160014bfe3f2baee0e4e0acb9a09564d85f95f64a08644fdffffff02a086010000000000225120c7da8b195d9e93cb321000adfd2c56ffe30969780cf4e09b782966e38d76761d70e1080000000000160014eee8c12b1093ef4780509809116f931b1fc6ea5adc8b0b00 SHA256: 06434a888fda769b0255deb79bc447555c60c28bfdbadfb9e6043b397e2eca4a Reverse byte order: 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 A few references:
This is understandable, but how to get this hash from json? ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced Code: { Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: nc50lc on October 05, 2022, 11:49:07 AM -snip- This is understandable, but how to get this hash from json?ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced Code: { In that specific case, it's the line that I left in the code snippet, it's the same as the one in my example. Now I saw where the confusion is. The "hash" ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced is the txid of the input of that example transaction. You can't get that hash from that transaction's sha256d result, it's only referencing that txid (& vout) to find the UTXO that it's trying to spend. What we want to get is the hash 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 in order to spend the example output. Like here, where it's spent: blockstream.info/tx/13fb6a1f56cd383ecbf90fd5b9463553f2fa4cacff34eb5ba99d991e4f74f6c4 (http://blockstream.info/tx/13fb6a1f56cd383ecbf90fd5b9463553f2fa4cacff34eb5ba99d991e4f74f6c4) As you can see, the first input is referencing 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 (vout: 0). Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: HoBzY on October 05, 2022, 12:17:18 PM -snip- This is understandable, but how to get this hash from json?ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced Code: { In that specific case, it's the line that I left in the code snippet, it's the same as the one in my example. Now I saw where the confusion is. The "hash" ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced is the txid of the input of that example transaction. You can't get that hash from that transaction's sha256d result, it's only referencing that txid (& vout) to find the UTXO that it's trying to spend. What we want to get is the hash 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 in order to spend the example output. Like here, where it's spent: blockstream.info/tx/13fb6a1f56cd383ecbf90fd5b9463553f2fa4cacff34eb5ba99d991e4f74f6c4 (http://blockstream.info/tx/13fb6a1f56cd383ecbf90fd5b9463553f2fa4cacff34eb5ba99d991e4f74f6c4) As you can see, the first input is referencing 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306 (vout: 0). Well, my goal is to study the blockchain, or rather, how mining and all its structures work, but I'm stuck on this txid, I can't figure out how to get it to add it to the structure chain and send RPC. I'm learning blockchain in less than a week I take the json object itself from blockchain.info Code: "inputs": [ I understand that 'tx_index = 220354657254222' is responsible for txid, but I don't understand how to get that hex txid is needed from it Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: nc50lc on October 05, 2022, 12:52:21 PM I take the json object itself from blockchain.info You can't get it from that transaction.Code: -snip- You can get it from this transaction: blockstream.info/tx/ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced?output:22 (http://blockstream.info/tx/ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced?output:22) which is what that outpoint is referring to. You or your wallet should already know that hash in order to "add it to the structure", you can't get it from the transaction being built For example, you can get a txid from your wallet's inbound transactions which you can also get with listunspent RPC, then use the txid of the one you want to spend as the outpoint. Title: Re: Pls Help!! How to get an outpoint in a transaction? #blockchain Post by: HoBzY on October 06, 2022, 07:43:38 AM I take the json object itself from blockchain.info You can't get it from that transaction.Code: -snip- You can get it from this transaction: blockstream.info/tx/ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced?output:22 (http://blockstream.info/tx/ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced?output:22) which is what that outpoint is referring to. You or your wallet should already know that hash in order to "add it to the structure", you can't get it from the transaction being built For example, you can get a txid from your wallet's inbound transactions which you can also get with listunspent RPC, then use the txid of the one you want to spend as the outpoint. ok thanks good forum) |