A Python-based Bitcoin mining application with GPU acceleration using NVIDIA CUDA technology. Even with the most powerful GPUs, this application cannot match the speed of dedicated ASIC mining devices. Therefore, it employs a random sampling strategy, hoping to find valid nonces faster than sequential iteration methods.
-
NVIDIA GPU with CUDA Support
- GPU must be compatible with CUDA toolkit
-
NVIDIA CUDA Toolkit (Version 10 or higher)
- Download from: https://developer.nvidia.com/cuda-downloads
- Ensure CUDA Toolkit is installed and available in system PATH
-
Python 3.x
- Required to run mining scripts
- liblooper.cu - CUDA kernel source code for sequential nonce scanning from 0 to 4,294,967,295 (0x00000000 - 0xFFFFFFFF)
- rr.cu - CUDA kernel source code for random nonce scanning
- build.bat - Compilation script for Windows (generates
.dllfiles) - build.sh - Compilation script for Linux (generates
.sofiles)
- looper.py - Python module serving as interface between
miner.pyand CUDA kernel (liblooper) - rrnonce.py - Python module serving as interface between
random_miner.pyand CUDA kernel (rr)
- miner.py - Mining application using random extranonce2 and full nonce scan (0-4294967295)
- random_miner.py - Mining application using random extranonce2 and random nonce
- test.py - Testing script for full scan and GPU hashrate benchmark (using block 933,995)
- test_1_block.py - Testing script using Bitcoin's first block header (Genesis Block)
- working_script.png - Screenshot of the application running
- Readme.md - This documentation file
For Windows:
build.batFor Linux:
chmod +x build.sh
./build.shThe compilation process will generate:
- Windows:
rr.dllandliblooper.dll - Linux:
rr.soandliblooper.so
Before starting mining, run tests to ensure CUDA kernels are working properly:
python3 test.pyThis script will:
- Test CUDA kernel functionality
- Measure your GPU's hashrate
- Display time required to complete full scan (0-4294967295)
Edit miner.py or random_miner.py according to your needs:
config = {
"pool_address": "public-pool.io", # Mining pool address
"pool_port": 3333, # Mining pool port
"user_name": "YOUR_BITCOIN_ADDRESS", # Replace with your Bitcoin address
"password": "x", # Password (usually "x" or "password")
"min_diff": 1, # Minimum difficulty (minimum is 1)
"poll_sleep": 0.05,
"reconnect_backoff": 5.0,
}Important Notes:
- Replace
user_namewith your own Bitcoin address min_diffminimum is 1 (kernel only outputs hash if difficulty ≥ 1)
Recommended for GPUs with hashrate > 4,294 MH/s
python3 miner.pyThis method will:
- Use random extranonce2
- Perform full nonce scan from 0 to 4,294,967,295
- Suitable for very powerful GPUs
Recommended for all GPUs
python3 random_miner.pyThis method will:
- Use random extranonce2
- Perform random nonce sampling (196,608,000 nonces per extranonce2)
- More efficient for medium-speed GPUs
If you're using random_miner.py and want to increase the number of nonces tried per extranonce2:
- Open
random_miner.pyfile - change batch_number in config:
config = {
"pool_address": "127.0.0.1",
"pool_port": 3333,
"user_name": "bc1qngzehzs73x2p5k7r7pa7na69ej89p40qxnrh60",
"password": "x",
"min_diff": 1,
"batch_number": 42, # 1.048.576 nonce per batch x 42 = 44.040.192 sample nonce per extranonce2
"poll_sleep": 0.05,
"reconnect_backoff": 5.0,
"max_extranonce2": 0xFFFFFFFF
}- If you want to change how many nonce launch per batch edit rr.cu`line 134, 135 int threadsPerBlock = 256; int blocksPerGrid = 4096; nonce launch per batch = 256 * 4096 = 1.048.576
- Recompile kernel by running
build.batorbuild.sh
- Mining pool sets target difficulty for each share
- Higher difficulty means harder to find valid shares
min_diffin configuration is the minimum difficulty the miner will search for
- Part of coinbase transaction that can be modified by miner
- Changing extranonce2 produces different merkle root
- Each extranonce2 provides 4,294,967,296 possible nonces
- Sequential (ASIC): Tries nonces 0, 1, 2, 3, ... in order
- Random (PyCudaBTCMiner): Tries random nonces hoping to find faster
When mining is running, you'll see output like:
[+] New Job ID detected! Switching to job: 6978d6ba00000709 Pool difficulty : 1.0
[✅] 02:16:09 Found Share!
Job ID: 6978d6ba00000709
EN2 : 755c8940
Nonce : d0ee7abf
Hash : 000000000fb1abc2d054395e4aaec12fb8c4d2d4a962056e4c656b6708b8c6
Diff : 260.99 (Target from pool: 1.00)
Hashrate : 4294.96 MH/s
- Ensure you've run the build script (
build.batorbuild.sh) - Verify
.soor.dllfiles exist in the same directory as Python scripts
- CUDA Toolkit is not installed or not added to PATH
- Download and install from: https://developer.nvidia.com/cuda-downloads
- Ensure latest NVIDIA drivers are installed
- Run
nvidia-smito check GPU status
- Your GPU may not be powerful enough for Bitcoin mining
- Try using
random_miner.pyfor better efficiency
If you encounter issues:
- Ensure all prerequisites are met
- Run
test.pyto verify CUDA kernel - Check error logs for details
- Create an issue on GitHub repository (if available)
Developer Notes:
- I use Linux for development
- Windows script (
build.bat) has not been thoroughly tested - If you encounter issues on Windows, please report them
License: Feel free to use for educational and experimental purposes. But if you succeed in getting block rewards, please donate to me, my btc address bc1qngzehzs73x2p5k7r7pa7na69ej89p40qxnrh60