mining swimming pools – Stratum protocol – downside with implementation in python


For a few days I am attempting to put in writing easy script in python to speak with stratum pool server. I am utilizing simplified code of NightMiner ( and a few testnet I’ve foud ( stratum+tcp://pool.bitcoincloud.web:4008), however I am unable to get the right outcome. Perhaps somebody extra skilled may assist me. Under I present every step of my script (step, no python supply code).

1. connect with the server, authorize, get the job information

After connecting to the server I ship this requests:

b'{"id": 1, "methodology": "mining.subscribe", "params": []}n'
b'{"params": ["testuser", "anything"], "id": 2, "methodology": "mining.authorize"}n'

and get the next response:


2. get the coinbase and merkle root

With this information and extranounce=”00000000″ I can construct the coinbase (in byte kind, however I’ll present as hex on this instance):


Subsequent factor to do is double hash the coinbase with SHA256 algo, which supplies as the next bytes:


There isn’t any merkle branches (merkle branches array is empty), so hash above is our merkle root.

3. constructing the header

With merkle root and information obtained in step 1, I can begin constructing a header:

header= model + prevhash + merkle root + ntime + nbits + nonce

I exploit the values as follows:

model - obtained '20000000', after little-endian conversion it's '00000020'
prevhash - obtained '4128bf630f57387b00e25b419d1bb77e667e4036a7d8fee80000015600000000', after conversion it's '63bf28417b38570f415be2007eb71b9d36407e66e8fed8a75601000000000000' (reverse bytes order each 4 bytes)
merkle root - get '9b9c9ab0b1c92844e4fed3f895f9443fefcda5ae02cc5a8ad4444f9303081a23' in step 2, stays that manner
ntime - obtained '5e148a8c', after conversion it's '8c8a145e'
nbits - obtained '1a02b098', after conversion it's '98b0021a'

So the header is

b'0000002063bf28417b38570f415be2007eb71b9d36407e66e8fed8a756010000000000009b9c9ab0b1c92844e4fed3f895f9443fefcda5ae02cc5a8ad4444f9303081a238c8a145e98b0021a' + nonce

4. search nonce

the problem is 0.01, so my goal is


after some calculations, I discover this 4 bytes to make use of it as a nonce:


so my full header is now


after double-hashing it with SHA256 algo and reverse bytes order I get this hash:


which is under my goal, so ‘d0cf1040’ ought to be the proper nonce.

5. submit nounce

last item to do is submitting the outcomes, so I ship this request to the server:

b'{"id":2, "methodology":"mining.submit","params":["testuser","4ca","00000000","5e148a8c","d0cf1040"]}n'

and that is response I get:


I don’t know why I get outcome=false. I can solely suppose there’s a mistake in step 3 (constructing header) and this error is expounded to byte-order of some values, however I am unable to discover this error (I’ve tried many variants of byte-order, however by no means get the response outcome=true).

I will likely be a lot obliged if anybody can test this calculations and provides me some ideas.

Supply hyperlink

Leave a reply