如何用Bash脚本创建Stratum套接字并连接SlushPool?
Got it, let's break this down first—your curl command failed for a simple but crucial reason: the Stratum mining protocol runs on raw TCP, not HTTP. SlushPool's 3333 port is a Stratum TCP endpoint, which doesn't understand HTTP POST requests at all. That's why you got an empty reply.
Bash-compatible Stratum Connection Script (Using Netcat)
Most Linux and macOS systems come with netcat (shortened to nc) pre-installed, which is perfect for establishing TCP connections and sending Stratum's JSON-RPC requests. Here's a simple, working script to run the mining.subscribe request:
#!/bin/bash # Configure your pool details STRATUM_POOL="stratum.slushpool.com" STRATUM_PORT="3333" # Build the mining.subscribe JSON request SUBSCRIBE_PAYLOAD='{"id": 1, "method": "mining.subscribe", "params": []}' # Send the request over TCP and capture the response # Note: Use `-c` instead of `-e` if you're on macOS (OpenBSD nc) echo -e "$SUBSCRIBE_PAYLOAD\n" | nc $STRATUM_POOL $STRATUM_PORT
Quick Notes on the Script:
echo -e "$SUBSCRIBE_PAYLOAD\n": Stratum requires JSON-RPC requests to end with a newline character—-elets us parse the\nescape sequence correctly.nc $STRATUM_POOL $STRATUM_PORT: This establishes a direct TCP connection to the pool's Stratum port, sends your request, and prints the pool's response to the terminal.
For macOS Users (OpenBSD Netcat):
If your nc is the OpenBSD variant (default on macOS), tweak the final line to include the -c flag:
echo -e "$SUBSCRIBE_PAYLOAD\n" | nc -c $STRATUM_POOL $STRATUM_PORT
What You'll See After Running the Script
Once executed, you should get a response matching the format you expected, something like:
{"id":1,"result":[["mining.notify","ae6812eb4cd7735a302a8a9dd95cf71f"],"08000002",4],"error":null}
Next Step: Authenticate with Your SlushPool Account
After subscribing successfully, you'll need to send a mining.authorize request to verify your account. Here's how to extend the script to handle both steps:
#!/bin/bash STRATUM_POOL="stratum.slushpool.com" STRATUM_PORT="3333" YOUR_USERNAME="your-slushpool-username.worker-name" YOUR_PASSWORD="your-worker-password" # Leave empty if you didn't set one ( # Send subscribe request first echo '{"id": 1, "method": "mining.subscribe", "params": []}' sleep 1 # Give the pool a moment to process the first request # Send authorization request echo "{\"id\": 2, \"method\": \"mining.authorize\", \"params\": [\"$YOUR_USERNAME\", \"$YOUR_PASSWORD\"]}" ) | nc $STRATUM_POOL $STRATUM_PORT
Just replace the placeholder values with your actual SlushPool worker details, and you'll get responses for both the subscribe and authorize requests.
内容的提问来源于stack exchange,提问作者Dave

