I have the following problem:

currently i am testing in my local regtest

I generated the following cb-tx for block at height 119: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03027700ffffffff0158bf122a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac00000000

there are some tx in the mempool for the other tx i take the txid from the getblocktemplate request

I reverse the byte order for all of those and for the txid of the cbtx aswell.

still, i get the following error: bad-txnmrklroot

when i generate a block using generatetoaddress in regtest, then use getblock and run my merkle function over the txids, the merkle root is correct which means it is a issue with the coinbase txid

i realized that the coinbase tx from the generatetoaddress rpc call has a second output with 0 satoshis. is it possible to remove this second output so i can test further?

maybe someone had the same issue.

thanks in advance.

1 Answer 1


Not including the second output would result in a different failure, although it is likely that that check has not been performed yet. The inclusion of that output is necessary if your block contains segwit transactions. That output has an OP_RETURN script that contains the witness merkle root - a merkle root over the wtxids of all of the transactions in the block.

However the specific error bad-txnmrklroot refers to just the normal merkle root being incorrect. It suggests that your code for generating the merkle root is simply incorrect.

  • my merkle root is correct (following txids to merkle:) "594965c2bee7f6c939a6169147e4ed4c34a2a0b0776d03264e9532d51692d4e6", "cbc45f050ec7f2b5f9b08c2c280046bbc9f7e2ac1e5e0a2f8d734a0f19d4f918", "dde614820003084cc76b039978ecf29b91fe0edc9f1f766ad229ed94f2358d51", "370e8307db3990b089269b40afcdc55597e49577a0ff5eee715f343cb11ea45a", "404c3ef9fcab48d3d6ec39f66c991d4554b34477eab2e68a8ef26a40c63caf8e", "0c821f76d1003204a2415fa8d0b75d5da97e04d60c5d759c10db8f66dc78edbb" I got the correct merkle root (88657de90640e52883dc88f8cadef1da6cea08cb377787f537e47c821512918e), so my code seems to be correct
    – FearXenon
    Oct 8, 2023 at 10:55
  • What makes you think that it is correct? Can you post the code that you used to generate it?
    – Ava Chow
    Oct 8, 2023 at 14:38
  • i generated the block with the generatetoaddress method since i wanted to compare txids and merkle root. the above txids are from the block, as is the merkle root I tested my merkle code with the txids and got the correct merkle root
    – FearXenon
    Oct 8, 2023 at 14:45
  • Then you're probably calculating the txid of your coinbase incorrectly.
    – Ava Chow
    Oct 8, 2023 at 14:49
  • when i only have a coinbase tx in the block it submits, which means the coinbase txid is theoretically correct, right?
    – FearXenon
    Oct 8, 2023 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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