<p>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.</p>
<p>However the specific error <code>bad-txnmrklroot</code> refers to just the normal merkle root being incorrect. It suggests that your code for generating the merkle root is simply incorrect.</p>

CC BY-SA 4.0
2023-10-08T10:55:02.070Z
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
CC BY-SA 4.0
2023-10-08T14:38:05.930Z
What makes you think that it is correct? Can you post the code that you used to generate it?
Ava Chow
CC BY-SA 4.0
2023-10-08T14:45:59.143Z
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
CC BY-SA 4.0
2023-10-08T14:49:38.713Z
Then you're probably calculating the txid of your coinbase incorrectly.
Ava Chow
CC BY-SA 4.0
2023-10-08T14:52:52.043Z
when i only have a coinbase tx in the block it submits, which means the coinbase txid is theoretically correct, right?
FearXenon
CC BY-SA 4.0
2023-10-08T16:23:45.997Z
Yes. A block with just the coinbase has the merkle root as just the coinbase txid.
Ava Chow
CC BY-SA 4.0
2023-10-07T17:57:02.257Z
2023-10-07T17:57:02.257Z
Ava Chow
<p>I have the following problem:</p>
<p>currently i am testing in my local regtest</p>
<p>I generated the following cb-tx for block at height 119: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03027700ffffffff0158bf122a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac00000000</p>
<p>there are some tx in the mempool
for the other tx i take the txid from the getblocktemplate request</p>
<p>I reverse the byte order for all of those and for the txid of the cbtx aswell.</p>
<p>still, i get the following error: bad-txnmrklroot</p>
<p>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</p>
<p>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?</p>
<p>maybe someone had the same issue.</p>
<p>thanks in advance.</p>

<coinbase-transaction>
bitcoin-cli generatetoaddress <numberofblocks> <address> has 2 outputs
FearXenon
# bitcoin-cli generatetoaddress <numberofblocks> <address> has 2 outputs

(Asked by: username_0 on 2023-10-07)

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.

**Tags:** coinbase-transaction


---

## 1 answers

### Answer by username_1 on 2023-10-07. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: 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  
> **username_1**: What makes you think that it is correct? Can you post the code that you used to generate it?  
> **username_0**: 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  
> **username_1**: Then you're probably calculating the txid of your coinbase incorrectly.  
> **username_0**: when i only have a coinbase tx in the block it submits, which means the coinbase txid is theoretically correct, right?  
> **username_1**: Yes. A block with just the coinbase has the merkle root as just the coinbase txid.  

---

