I need a Python(2 or 3) Monero miner that outputs hashes to terminal.

Please ask me if you need clarification.

  • Could this work, with some modifications? Also, I forgot where I found this so if it looks familiar to you, please link me to it. import socket import json import hashlib import binascii from pprint import pprint import time import random import os import binascii import pycryptonight import struct address = '' #Enter pool info here password = '' nonce = hex(random.randint(0,2**32-1))[2:].zfill(8) host = '' port = 0000 print("address:{} nonce:{}".format(address,nonce)) print("host:{} port:{}".format(host,port)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host,port)) Feb 6, 2019 at 14:27
  • If I can only hash with cryptonightv2, what coins can i mine? Feb 6, 2019 at 14:43

1 Answer 1


I'm assuming this is a follow-up question to your previous question.

Here is an example that shows how to hash a block hashing blob with a supplied nonce:

import binascii
import pycryptonight
import struct

bhb = binascii.unhexlify("070786a498d705f8dc58791266179087907a2ff4cd883615216749b97d2f12173171c725a6f84a00000000fc751ea4a94c2f840751eaa36138eee66dda15ef554e7d6594395827994e31da10")
nonce = 1234
bin = struct.pack('39B', *bytearray(bhb[:39]))
bin += struct.pack('I', nonce)
bin += struct.pack('{}B'.format(len(bhb)-43), *bytearray(bhb[43:]))
hash = pycryptonight.cn_slow_hash(bin, 2)

Where bhb is the binary of a blockhashing_blob as returned from a call to get_block_template, and nonce is your nonce for this particular hash.

To create a miner, follow the steps in my answer to your other question.

  • I get an error when I run this: Traceback (most recent call last): File "miner.py", line 7, in <module> bin = struct.pack('38c', *bhb[:38]) struct.error: char format requires a bytes object of length 1 Feb 5, 2019 at 3:43
  • Written and tested for Python 2. You are trying in Python 3.x
    – jtgrassie
    Feb 5, 2019 at 3:49
  • Whilst this isn't a Python support SE, I have updated so it will work in Python 2 & 3 now.
    – jtgrassie
    Feb 5, 2019 at 4:08
  • Ok, so I got it to work. Thanks! but, it when it outputs to the terminal, it has a 'b' in front of the cryptonight hash. b'547951be7d8843bbf48ef6f69b59380f9b5225e2b6a3aa115ea16e53439ee0d4' Feb 5, 2019 at 14:52
  • And also, do hashes hashed change based on the bhb? Feb 5, 2019 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.