Created
November 13, 2021 00:30
-
-
Save GEEGABYTE1/42db8a5813655435ac22e8da2e1a8a36 to your computer and use it in GitHub Desktop.
Sample Basic Mining Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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