Skip to content

Instantly share code, notes, and snippets.

@GEEGABYTE1
Created November 13, 2021 00:30
Show Gist options
  • Save GEEGABYTE1/42db8a5813655435ac22e8da2e1a8a36 to your computer and use it in GitHub Desktop.
Save GEEGABYTE1/42db8a5813655435ac22e8da2e1a8a36 to your computer and use it in GitHub Desktop.
Sample Basic Mining Function
import hashlib
import random
nonce_limit = 1000000000
zeroes = random.randint(1, 100)
def mine(block_num, transaction_hash, previous_hash):
for nonce in range(nonce_limit):
base_text = str(block_num) + transaction_hash + previous_hash + str(nonce)
hash_try = hashlib.sha256(base_text.encode()).hexdigest()
if hash_try.startswith('0' * zeroes):
print("Found hash with nonce: {}".format(nonce))
return hash_try
return None
block_number = 24
transactions = '761234fcc142'
previous_hash = "876de8756b967c87"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment