Bitcoin Lottery Miner

Learn about Bitcoin Mining and get rich. Maybe.

How It Works & Instructions
What is Bitcoin Mining?

Bitcoin mining is the process that secures the network and creates new bitcoins. It's not a "puzzle" in the traditional sense, but a brute-force race of guessing. Miners take the data for a new block (which includes recent transactions) and add a random number called a "nonce". They then put this combined data through a one-way cryptographic function called SHA-256, which produces a unique, unpredictable string of characters called a "hash".

The goal is to find a nonce that results in a hash that is numerically lower than the network's current "target" value. Since the output of SHA-256 is unpredictable, the only way to find such a hash is by guessing trillions of different nonces per second.

The first miner to find a valid hash wins the right to add their block to the blockchain and receives the reward: brand new bitcoin (the block subsidy) plus all transaction fees from that block. This "Proof-of-Work" system is what makes it computationally expensive and difficult to attack the network, thus keeping it secure.

Solo Mining vs. Pool Mining

Finding a block by yourself is called "solo mining". Because the Bitcoin network is so large and competitive, the chance of a single person finding a block is incredibly small—like winning a major lottery. However, if you do, you get to keep the entire block reward. This app's "Advanced Mode" lets you try exactly that.

"Pool mining" is when thousands of miners combine their guessing power. When one of them finds a block, the reward is split among everyone in the pool based on how much work they contributed. This provides smaller, more frequent payments and is how most mining is done today.

Simulation Mode Guide

This is the default, safe, and educational mode. It uses real data from the Bitcoin network but doesn't actually broadcast anything. This means you can't earn real money, but you also can't lose anything. It's the perfect way to learn.

It has two sub-modes:

  • Live Mining: This simulates mining on the very latest, current Bitcoin block. It pulls real-time data to give you an accurate picture of what's happening on the network right now.
  • Time Machine: This lets you load the data from a historical block from Bitcoin's past. Because the network difficulty was much lower in the early days, you can experience what it was like to mine with a regular CPU and have a realistic chance of finding a valid block hash in seconds! Try mining block #1000, for example.
Advanced (Pool) Mode Guide

This mode connects to a real mining pool for a chance to win real Bitcoin. This is for advanced users, as it requires running a separate program on your computer called a WebSocket proxy.

Why is a proxy needed?

Web browsers cannot directly connect to mining pools, which use a standard network protocol called TCP. The WebSocket proxy acts as a translator, converting the browser's WebSocket connection into a TCP connection that the pool can understand.

How to Set Up the Proxy:

  1. Install Node.js on your computer (this allows you to run JavaScript files outside of a browser).
  2. Create a new file on your computer named proxy.js.
  3. Copy the complete code block from the box below and paste it into your `proxy.js` file.
  4. Open a command line tool (like Terminal on Mac or PowerShell/CMD on Windows), navigate to the folder where you saved `proxy.js`, and run the command: npm install ws. This installs the necessary library.
  5. Start the proxy by running the command: node proxy.js. You should see a message "Proxy server started...". Leave this terminal window open while you mine.
  6. Back in this web page, switch the miner to "Advanced (Pool)" mode.
  7. Enter your own Bitcoin payout address in the "Stratum Username / Payout Address" field. This is where your reward will be sent if you find a block.
  8. Click "Start Mining". You should see messages in the Event Log and in your terminal window confirming the connection.

Note: The proxy below is pre-configured to connect to `eusolo.ckpool.org` on port `3333`. You can edit these values in the `proxy.js` file if you wish to use a different pool.

const WebSocket = require('ws');
const net = require('net');

// --- Configuration ---
const WEB_SOCKET_PORT = 8080; // Port for the browser to connect to
const STRATUM_HOST = 'eusolo.ckpool.org';
const STRATUM_PORT = 3333;

const wss = new WebSocket.Server({ port: WEB_SOCKET_PORT });

wss.on('connection', (ws) => {
    console.log('Browser connected to proxy.');
    const stratumClient = new net.Socket();
    const messageBuffer = [];
    let isPoolConnected = false;

    // Connect to the Stratum pool
    stratumClient.connect(STRATUM_PORT, STRATUM_HOST, () => {
        console.log(`Proxy connected to Stratum pool: ${STRATUM_HOST}:${STRATUM_PORT}`);
        isPoolConnected = true;
        // Send any buffered messages
        messageBuffer.forEach(msg => {
            console.log('Browser -> Pool (from buffer):', msg);
            stratumClient.write(msg + '\n');
        });
        messageBuffer.length = 0; // Clear the buffer
    });

    // Handle messages from the browser
    ws.on('message', (message) => {
        const msgStr = message.toString();
        if (isPoolConnected) {
            console.log('Browser -> Pool:', msgStr);
            stratumClient.write(msgStr + '\n');
        } else {
            console.log('Buffering message from browser:', msgStr);
            messageBuffer.push(msgStr);
        }
    });

    // Handle data from the pool
    stratumClient.on('data', (data) => {
        const messages = data.toString().split('\n');
        messages.forEach(msg => {
            if (msg.trim()) {
                console.log('Pool -> Browser:', msg);
                // Ensure the WebSocket is still open before sending
                if (ws.readyState === WebSocket.OPEN) {
                    ws.send(msg);
                }
            }
        });
    });

    // Handle errors
    stratumClient.on('error', (err) => {
        console.error('Stratum connection error:', err.message);
        ws.close();
    });

    ws.on('error', (err) => {
        console.error('WebSocket error:', err.message);
    });

    // Handle closing connections
    stratumClient.on('close', () => {
        console.log('Stratum connection closed.');
        isPoolConnected = false;
        ws.close();
    });

    ws.on('close', () => {
        console.log('Browser connection closed.');
        stratumClient.destroy();
    });
});

console.log(`WebSocket to TCP proxy server started on ws://localhost:${WEB_SOCKET_PORT}`);
Manual Mining Guide

The "Manual Mining" tool is a learning feature available in Simulation Mode. It allows you to step through the hashing process one guess at a time.

You can enter a nonce value yourself and see exactly how the block header is constructed and how the two SHA-256 hashes are calculated. It will then show you if your resulting hash is a valid solution by comparing it to the network target. This is a great way to visualize what your computer is doing millions of times per second when it's mining automatically.

Controls

Live Telemetry

Status: Stopped
BTC Price: Loading...
Hashrate: 0 H/s
Total Hashes: 0
Block Height: N/A
Difficulty: N/A
Best Share Diff:0
Accepted Shares:0
Est. Time to Block:N/A

Your Hashrate (MH/s)

Event Log

Achievements