0

I'm trying to get the raw transaction hex string of a transaction that I know the id from.

I would like to do that without using txindex=1.

As I assume the transaction is unspent (and confirmed) I'm doing the following steps:

bitcoin-cli gettxout 'txid'

bitcoin-cli getblockcount

bitcoin-cli getblockhash 'blockcount - txout.confirmations + 1'

bitcoin-cli getrawtransaction 'txid' 0 'blockhash'

I have a race condition when getting the blockcount.

Is there a better way to do that?

0

To avoid a race condition with getblockcount, you could use getblockheader with the bestblock result from gettxout and get its height. Then do the height calculation with the number of confirmations to get the block hash to pass to getrawtransaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.