Creating a Bitcoin Miner with Python

5 replies 500 views
proto2018Member
Posts: 1 · Reputation: 107
#1Nov 22, 2017, 09:11 AM
I'm looking for some real Python code to help me with actual bitcoin mining. Can anyone lend a hand? I found a script that only simulates the process but doesn't do the real thing. import hashlib import time def calculate_hash(block_header): return hashlib.sha256(block_header.encode()).hexdigest() def mine_block(previous_hash, transactions, difficulty): nonce = 0 start_time = time.time() while True: block_header = f"{previous_hash}{transactions}{nonce}" block_hash = calculate_hash(block_header) if block_hash[:difficulty] == '0' * difficulty: end_time = time.time() print(f"Block mined!") print(f"Hash: {block_hash}") print(f"Nonce: {nonce}") print(f"Time taken: {end_time start_time:.2f} seconds") print(block_header) return block_hash, nonce nonce += 1 # Example usage previous_hash = '0000000000000000000000000000000000000000000000000000000000000000' transactions = 'tx1->tx2->tx3' difficulty = 4 # Number of leading zeros required in the hash mine_block(previous_hash, transactions, difficulty)
5 Reply Quote Share
hash_bossLegendary
Posts: 1166 · Reputation: 5261
#2Nov 22, 2017, 10:49 AM
To get? You could find that easily from quick google search. For example, i found these, https://bitcointalk.org/index.php?topic=3546.0 https://github.com/muimota/miniminer Note that i haven't tried any of those, where I'm not responsible if those doesn't work or do anything malicious. And please stop performing SEO spam.
3 Reply Quote Share
maxi2017Senior Member
Posts: 262 · Reputation: 1550
#3Nov 24, 2017, 01:03 AM
Wait a minute! Are you really that stupid?  So you are the same idiot "fromindia" who you recently claimed hacked your wallet and stole your funds?  Why did you make that whole story up? See here for reference:
0 Reply Quote Share
LuckyCoinLegendary
Posts: 832 · Reputation: 4795
#4Nov 24, 2017, 02:29 AM
If you are trying to build an application in python for real-life mining, you can't really build the SHA256d hashing part. You can only really build the part that receives all of the hashes generated thus far by the mining hardware and send them to a pool like ViaBTC's and retrieve the next range back from it.
2 Reply Quote Share
hash_bossLegendary
Posts: 1166 · Reputation: 5261
#5Nov 24, 2017, 02:40 AM
Whether it's SEO spam or selling ads, you violate these forum rules. You're right, although OP never say anything about profitable mining. And i feel OP just want excuse to perform SEO spam or selling ads while responding to our reply.
2 Reply Quote Share
LuckyCoinLegendary
Posts: 832 · Reputation: 4795
#6Nov 24, 2017, 06:14 AM
@julia335, if you are trying to sell something, you need to move this topic to the Marketplace board.
3 Reply Quote Share

Related topics