Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: BigManComputer on August 23, 2017, 10:47:50 PM



Title: C++ --- How to send a request to a Bitcoin mining pool for Block header
Post by: BigManComputer on August 23, 2017, 10:47:50 PM
Hey! This has had me stumped for a while. I am quite new to networking in c++, however, I do have fundamental knowledge.

I was wondering how exactly I send a request to a Bitcoin mining pool to request block header information from a pool in c++. I have done much research myself into this, and so far haven't found a solution. I would prefer to use the newer Getblocktemplate protocol, however, I am fine with an answer regarding the Getwork protocol.

I am aware I must send a request to a pool, in the form of a JSON snippet, and the server will respond with the current Block's information, also in the form of a JSON snippet. A have received this information from  here: https://en.bitcoin.it/wiki/Getblocktemplate (https://en.bitcoin.it/wiki/Getblocktemplate)    and from many other sources, however, nobody explicitly said how to send a request to the pool, and no examples of c++ code were given.

If somebody could help me I would greatly appreciate it...
Thanks  :)


Title: Re: C++ --- How to send a request to a Bitcoin mining pool for Block header
Post by: achow101 on August 23, 2017, 11:24:53 PM
There are two main protocols used for getting block information, stratum and getblocktemplate. For either one, you have to connect to the url for a pool's stratum or getblocktemplate server. Then from there you follow the respective protocol to request data from the server.

Information on how to use the stratum protocol is found here: https://slushpool.com/help/manual/stratum-protocol
Basically you just open up a tcp connection and send it specific JSON data and you will get a reply. You can do this manually by using netcat.

Information on how to use getblocktemplate can be found here: https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki and https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki
Basically you just connect to the server and send it HTTP POST requests.


Title: Re: C++ --- How to send a request to a Bitcoin mining pool for Block header
Post by: BigManComputer on August 24, 2017, 09:29:40 AM
Thanks for the reply! :)
I had an idea that remote procedure calls may have been involved...
I will look into this when I get back to my computer...