• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

bitcoind – How to build coinbase transaction from bitcoin core?

Moussa by Moussa
February 23, 2026
in Bitcoin
0
How do Bitcoin mining pools typically handle payout frequency versus thresholds?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


My question is: In BTC ADRESS i put any adress that i choose from my bitcoin-qt wallet?

Yes!! You would basically use a generated receiving address belonging to your btc wallet and use that as your value within the createrawtransaction address parameter field.

Although you would need to call the getnewaddress command via any means available to you after which you can make use of it.

.

Assuming that you’ve already changed directory to where your bitcoin-cli or bitcoind executable file is located

CMD approach would look something like this:

bitcoin-cli getnewaddress which would display newly generated address in the cmd terminal window.

bitcoin-cli getnewaddress > newlygenerated_BTC_address.txt which would store the output into a text file

To make things more dynamic you would need to write a batch script to handle aspects that your programming language isn’t able to handle. But hopefully you get the idea.





And if i double hash the given hex result returned to me, without adding any other transaction, this can be the merkleroot (with only the coinbase transaction) and use it to build the blockheader?

Yes. You would insert the double hashed result of the raw transaction data as the merkleroot without swapping it( That will be done later when swapping the blockheader for mining). If you swap twice, you’ll end up with an incorrect coinbase hash.

Related articles

FBI Reports $11.37B in Crypto Scam Losses as US Fraud Hits Record High – Crypto News Bitcoin News

FBI Reports $11.37B in Crypto Scam Losses as US Fraud Hits Record High – Crypto News Bitcoin News

April 7, 2026
How do Bitcoin mining pools typically handle payout frequency versus thresholds?

timestamp – Using the blockchain for providing other services, besides bitcoin transactions

April 7, 2026

Other than that, you would need to correct and insert a few things.

Assuming hex response of createrawtransaction produces -> 02000000010000000000000000000000000000000000000000000000000000000000000000ffffff7f00ffffffff0140be402500000000160014f68d712fa6f49cdfaaa1707a9d0234e2aabb3f1100000000

:::


02000000010000000000000000000000000000000000000000000000000000000000000000ffffff7f00ffffffff0140be402500000000160014f68d712fa6f49cdfaaa1707a9d0234e2aabb3f1100000000

____________________________________________________________________

02000000 - Tx version -- 8 bytes
____________________________________________________________________

01 - input count -- 2 bytes
____________________________________________________________________

0000000000000000000000000000000000000000000000000000000000000000 - txid -- 64 bytes
____________________________________________________________________

ffffff7f - vout -- 8 bytes
____________________________________________________________________

00 - size of scriptsig -- MAX OF 100 bytes
____________________________________________________________________

 - scriptsig size is missing - hexadecimal value
 - byte push is missing - hexadecimal value
 - block height (little endian) is missing - hexadecimal value
 - arbitrary data(extranonce/message) is missing - hexadecimal value
____________________________________________________________________

ffffffff - input sequence -- 8 bytes
____________________________________________________________________

01- number of output -- 2 bytes
____________________________________________________________________

40be402500000000 - reward/Output Value -- 16 bytes
____________________________________________________________________

160014f68d712fa6f49cdfaaa1707a9d0234e2aabb3f11 - scriptPubkey -- 46 bytes (dynamic in length)
____________________________________________________________________

00000000  - locktime
____________________________________________________________________


My C++ solution :


bHeight - Block height as given by **```getblocktemplate```** response 
Headers needed - sstream, string, iostream.
Namespaces used - using std::stringstream, using std::string.


string SwapBlockHeight(string data)
{
    string bits; // global return variable
    if(data.size() == 5)
    {
        string byte1, byte2, byte3;
        byte3 = data.substr(5, 2);
        byte2 = data.substr(3, 2);
        byte1 = data.substr(1, 2);
        bits = byte3 + byte2 + byte1;
    }
    else if(data.size() == 6)
    {
        string byte1, byte2, byte3;
        byte3 = data.substr(4, 2);
        byte2 = data.substr(2, 2);
        byte1 = data.substr(0, 2);
        bits = byte3 + byte2 + byte1;
    }
    else if(data.size() == 8)
    {
        string byte1, byte2, byte3, byte4;
        byte4 = data.substr(6, 2);
        byte3 = data.substr(4, 2);
        byte2 = data.substr(2, 2);
        byte1 = data.substr(0, 2);
        bits = byte4 + byte3 + byte2 + byte1;
    }
    return bits;
}



string GETLittleEndian_BlockHeight(uint32_t bHeight)
{
    string reversedDATA;
    char i[25];
    sprintf(i, "%x", bHeight);
    stringstream aa;
    aa << i;
    aa >> reversedDATA;
    // reversedDATA = SwapBlockHeight(reversedDATA);
    // Optimized approach of above function call is applied below
    // Assuming hex conversion result is = "1d34f589"
    string byte;

    // Optimized approach
    for (int i = 0, k = 0; i < reversedDATA.length()/2; i++)
    {
        byte += reversedDATA.substr(k, 2);
        k+=2;
    }
    reversedDATA = byte; // or you could just return byte itself
    // reversedDATA.length()/2 - because we will be done with our goal in half the total size.

    return reversedDATA;
}


Bytepush = "03";
Blockheight_littleEndian = GETLittleEndian_BlockHeight(bHeight);
ArbitraryData = "abcdefgh"; // Anything within 100 bytes .. 1 char == 2 bytes

scriptsig_Size = Bytepush.length() + Blockheight_littleEndian.length() + ArbitraryData.length();

// ALL VALUES ARE HEXADECIMAL


LOOKING FOR JSON PARSER/SERIALIZATION??

  1. Get nlohmann json library
  2. Include in project folder

A little batch script used but nothing too advanced.

#include "json.hpp" // for json serialization parser
#include  // for ifstream
#include  // for system calls
#include "windows.h" // if on windows
using namespace nlohmann;
using std::ifstream;


inline void RunCommand_With_Output_Without_SYMBOL_Defined(string Command_To_Run, string Output_FileName)
{
    string xx_combine = Command_To_Run + " >" + Output_FileName;
    char run_command[xx_combine.length()];
    strcpy(run_command, xx_combine.c_str());
    system(run_command); // execute the command 
// std::cout << ifstream(Output_FileName).rdbuf(); // print to console -- FOR DEBUGGING ONLY!!
} // Successfully compiled on 20/01/2022 10:20PM


void GETBLOCKTEMPLATE()
{
    string getblocktemplate_syntax = "cd \"C:\\Users\\YOUR DESKTOP NAME\\Desktop\\Z Code\" && call gt.bat";
    string filename = "getblocktemplate_Response.json"; // Create file Name
    RunCommand_With_Output_Without_SYMBOL_Defined(getblocktemplate_syntax, filename); // create json file with getblockresponse output
} // Successfully compiled on 31/01/2022 11:30AM



uint32_t Get_BLOCK_HEIGHT_asInteger()
{
    uint32_t f;
    ifstream file_input("getblocktemplate_Response.json");
    json object = json::parse(file_input); // Parse json data
    file_input.close(); // close streamer
    f = object.at("height");
    return f;
}

WHATS INSIDE THE .BAT FILE??

gt.bat

@echo off
cd "C:\Users\YOUR DESKTOP NAME\Desktop\Z Code" && bitcoin-cli getblocktemplate {\"rules\":[\"segwit\"]}

rem or

cd "C:\Users\YOUR DESKTOP NAME\Desktop\Z Code" && bitcoin-cli getblocktemplate {\"rules\":[\"segwit\"]} 

Rem copy file created to destination folder
copy "C:\Users\YOUR DESKTOP NAME\Desktop\Z Code\getblocktemplate_Response.json" "C:\Users\YOUR DESKTOP NAME\Desktop\Z Code\COINBASE ONLY\BITCOIN_Miner"

NOTE!! – Copying of json file from one path to another is only needed if your gt.bat is not located in your project root folder along with header files. This would cause errors later on because in as much as the json file was created and holds block template response, it won’t be found UNLESS you tell the json reader to go into whichever folder where it will be generated and get it from there.

It’s a lot more than requested but others might find the info useful.
I’ll create a repository on github later.

Ignore what you don’t need.

Cheers



Source link

Share76Tweet47

Related Posts

FBI Reports $11.37B in Crypto Scam Losses as US Fraud Hits Record High – Crypto News Bitcoin News

FBI Reports $11.37B in Crypto Scam Losses as US Fraud Hits Record High – Crypto News Bitcoin News

by Moussa
April 7, 2026
0

Key Takeaways: FBI IC3 logged $11.37B crypto losses in 2025, up 22% YoY across 181,565 complaints. Investment scams drove $7.2B...

How do Bitcoin mining pools typically handle payout frequency versus thresholds?

timestamp – Using the blockchain for providing other services, besides bitcoin transactions

by Moussa
April 7, 2026
0

What I have in mind are proof of existence software, than are a kind a non-centralized and virtual notary service....

XRP Price Hinges on Senate CLARITY Act — Why This Bill Matters

XRP Price Hinges on Senate CLARITY Act — Why This Bill Matters

by Moussa
April 7, 2026
0

XRP is trading at $1.34 – down more than 63% from its July 2025 peak of $3.65 and coming off...

Finance CEO Raoul Pal Calls The Bitcoin Peak, And You Won’t Believe The Numbers

Finance CEO Raoul Pal Calls The Bitcoin Peak, And You Won’t Believe The Numbers

by Moussa
April 7, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure Financial economist and CEO of Real Vision,...

XRP Wallet Count Tops 8 Million As Trading Volume Nears $4 Billion

XRP Wallet Count Tops 8 Million As Trading Volume Nears $4 Billion

by Moussa
April 7, 2026
0

More than 8 million wallets now hold XRP — a milestone that comes even as the token’s price sits well...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwdG5wLXN1YnNjcmlwdGlvbiUyMiUzRSUwQSUzQ2Zvcm0lMjBtZXRob2QlM0QlMjJwb3N0JTIyJTIwYWN0aW9uJTNEJTIyaHR0cHMlM0ElMkYlMkZhcHByb3gub3JnJTJGJTNGbmElM0RzJTIyJTNFJTBBJTBBJTNDaW5wdXQlMjB0eXBlJTNEJTIyaGlkZGVuJTIyJTIwbmFtZSUzRCUyMm5sYW5nJTIyJTIwdmFsdWUlM0QlMjIlMjIlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1maXJzdG5hbWUlMjIlM0UlM0NsYWJlbCUyMGZvciUzRCUyMnRucC0xJTIyJTNFRmlyc3QlMjBuYW1lJTIwb3IlMjBmdWxsJTIwbmFtZSUzQyUyRmxhYmVsJTNFJTBBJTNDaW5wdXQlMjBjbGFzcyUzRCUyMnRucC1uYW1lJTIyJTIwdHlwZSUzRC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w_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News