• 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

Bitcoin’s Wild Swings Go Quiet, Even As The Bears Won’t Let Go

Bitcoin’s Wild Swings Go Quiet, Even As The Bears Won’t Let Go

August 19, 2026
UAE Pulls Iran Trade Plug as Hormuz Crisis Rattles Global Markets

UAE Pulls Iran Trade Plug as Hormuz Crisis Rattles Global Markets

August 19, 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

Bitcoin’s Wild Swings Go Quiet, Even As The Bears Won’t Let Go

Bitcoin’s Wild Swings Go Quiet, Even As The Bears Won’t Let Go

by Moussa
August 19, 2026
0

Bitcoin is deep into its bear market, though it’s doing something it doesn’t typically do: sit still.  That’s according to...

UAE Pulls Iran Trade Plug as Hormuz Crisis Rattles Global Markets

UAE Pulls Iran Trade Plug as Hormuz Crisis Rattles Global Markets

by Moussa
August 19, 2026
0

Key TakeawaysThe S&P 500 fell about 0.7% on Aug. 18 as semiconductor stocks led a technology selloff.The UAE halted Iran...

What does "extended key is not unique" in Sparrow wallet mean?

by Moussa
August 18, 2026
0

I created a M-of-N multisig wallet with Sparrow, where each of the N keystores is defined using a 24 word...

Sam Altman ChatGPT AI Predicts Bitcoin Price, and its Bullish

Sam Altman ChatGPT AI Predicts Bitcoin Price, and its Bullish

by Moussa
August 18, 2026
0

Bitcoin has endured a difficult 2026 so far, and the remainder of the year could prove just as volatile. After...

SEC Delaying Plan To Allow Crypto Versions Of US Stocks

SEC Proposes Crypto Rulebook As Clarity Act Stalls

by Moussa
August 18, 2026
0

The Securities and Exchange Commission has proposed its own framework for crypto asset offerings, pressing ahead while landmark legislation stalls. ...

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

© 2024 APPROX FOUNDATION - The Crypto Currency News