Learn about Bitcoin Mining and get rich. Maybe.
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.
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.
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:
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.
npm install ws
. This installs the necessary library.node proxy.js
. You should see a message "Proxy server started...". Leave this terminal window open while you mine.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}`);
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.
Mine a historical block!