2

I have been wondering how to make a Python Monero miner. I know about py-cryptonight, but does anyone know anything about how to actually code with it? I understand that cn_slow_hash is for mining, but when I try to create a hash, I get a bunch of random characters. I know that Python miners are slow, but this is just an experiment. I know how to code in Python fairly well, but not great. Can someone please guide me along? Thanks!

1
  • Feel free to edit and re-tag my post Jan 29, 2019 at 1:28

1 Answer 1

7

The general steps are as follows:

  1. Call your Monero daemon's RPC method get_block_template.
  2. Take the blockhashing_blob from the response and convert the hex to binary.
  3. Set a 4 byte nonce in bytes 39..42
  4. Hash the data with cn_slow_hash, you'll get 32 bytes back, that's your hash. Note, this result hash is binary - it's a 32 byte number. If you want to display it, you need to convert it to a hex string.
  5. Compare the result hash against the next block difficulty (again, converted to binary). The calculation to see if your hash meets the difficulty is as follows:
    • b / h (where b is the base difficulty, 2^256-1, and h is your result hash)
    • If the result is greater than or equal to the next block difficulty (as returned from get_block_template at step 1), you've mined a block and can submit it to the network using the RPC call submit_block.
    • If it's not, repeat from step 3 with a new nonce.

Doing this all in Python is pretty straightforward because Python supports big numbers, but, it will be terribly slow.

I've omitted specifically how to call cn_slow_hash as the README already shows how trivial it is to call.

4
  • Hi, How could you do this? I'm not super experienced but I'll try. Jan 30, 2019 at 0:08
  • Also, would cryptonight version would this be(for example, cryptonight v8, cryptonight heavy, etc) Jan 30, 2019 at 0:23
  • More specifically, how do you add the 4 byte nonce in bytes 39..42? Jan 30, 2019 at 0:34
  • "How could you do this?" <- If I give any more guidance I'll be writing it for you! "Also, would cryptonight version would this be" <- The question was for Monero, so CryptoNight v2. "how do you add the 4 byte nonce" <- change bytes 39..42 to any random values.
    – jtgrassie
    Jan 30, 2019 at 1:47

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .