2.4 KiB
2.4 KiB
Bitcoin Mining Simulation
Overview
This project is a simple Python simulation of Bitcoin mining. It demonstrates the core concepts of blockchain mining, such as generating transactions, calculating hashes, and solving proof-of-work problems by finding a valid nonce.
Features
- Random transaction generation.
- SHA-256 hashing of block data.
- Proof-of-work implementation with adjustable difficulty.
- Simulation of blockchain block creation.
Requirements
- Python 3.6+
Installation
- Clone the repository or download the source code:
git clone <repository-url>
Usage
- Run the script:
python main.py - The program will generate random transactions, mine blocks, and display the resulting hashes.
Example Output
Mining Block 1 with Transactions: 12345->67890->50; 54321->09876->30; 11111->22222->20
Block found! Nonce: 45678, Hash: 00000f9d6c24...
New Hash: 00000f9d6c24...
Configuration
The script contains configurable constants to adjust the mining simulation:
MAX_NONCE: Limits the number of nonce iterations for mining. Default is1,000,000.DIFFICULTY: Specifies the number of leading zeros required in the hash. Default is6.
To modify these values, edit the script directly:
MAX_NONCE = 1000000 # Set a higher or lower limit as needed
DIFFICULTY = 6 # Adjust difficulty for faster or slower mining
Project Structure
mining_simulation.py: Main script containing all functionality for the simulation.
How It Works
- Transaction Generation: Random transactions are created with a sender, receiver, and amount of bitcoins.
- Hash Calculation: Each block is hashed using SHA-256.
- Proof-of-Work: The script iterates through possible nonce values to find a hash matching the difficulty.
- Blockchain Simulation: Each block references the previous block's hash, forming a simple blockchain.
Limitations
- This is a simplified simulation and does not represent the full complexity of real-world Bitcoin mining.
- The script is single-threaded and not optimized for performance.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions
Contributions are welcome! Feel free to fork the repository and submit pull requests.
Contact
For questions or suggestions, please reach out to [your email or GitHub profile].