For a few days I am making an attempt 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 correct end result. Possibly somebody extra skilled might assist me. Under I present every step of my script (step, no python supply code).

1. hook up 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:

{"id":1,"end result":[[["mining.set_difficulty","deadbeefcafebabea200000000000000"],["mining.notify","deadbeefcafebabea200000000000000"]],"40000004",4],"error":null}

2. get the coinbase and merkle root

With this information and extranounce=”00000000″ I can construct the coinbase (in byte type, 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 is no such thing as a merkle branches (merkle branches array is empty), so hash above is our merkle root.

3. constructing the header

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

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

I take advantage of the values as follows:

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

So the header is

b'0000002063bf28417b38570f415be2007eb71b9d36407e66e8fed8a756010000000000009b9c9ab0b1c92844e4fed3f895f9443fefcda5ae02cc5a8ad4444f9303081a238c8a145e98b0021a' + nonce

4. search nonce

the issue is 0.01, so my goal is


after some calculations, I discover this Four 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

final thing 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:

{"id":2,"end result":false,"error":null}

I do not know why I get end result=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 end result=true).

I can be a lot obliged if anybody can verify this calculations and provides me some suggestions.

Source link


Please enter your comment!
Please enter your name here