Stratum connection for bitcoin pool mining

0 votes

I'm programming a Bitcoin miner that mines in a pool using the stratum protocol (see documentation here.

The stratum protocol uses JSON-RPC 2.0 as its encoding and according to the JSON-RPC 2.0 specification(specification here) I should use sockets to create a connection to the pool.

My problem is that I don't seem to be able to receive a response back from the pool. JSON-RPC 2.0 states that for every Request object that I send, I must receive a response back.

Here is my code:

public static void main(String[] args) { connectToPool("stratum.slushpool.com", 3333); } static void connectToPool(String host, int port) { try { InetAddress address = InetAddress.getByName(host); out.println("Atempting to connect to " + address.toString() + " on port " + port + "."); socket = new Socket(address, port); String message1 = "{\"jsonrpc\" : \"2.0\", \"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}"; PrintWriter output = new PrintWriter(socket.getOutputStream(), true); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); output.write((message1 + "\\n")); out.println(input.readLine());//Hangs here. } catch (IOException e) { out.println(e.getMessage()); out.println("Error. Can't connect to Pool."); System.exit(-2); 
    } 
}


 

Apr 5, 2022 in Blockchain by Rahul
• 9,670 points
1,315 views

1 answer to this question.

0 votes

After hours of tinkering around I have found the solution. Apparently the JSON string shouldn't have any spaces. So instead of:

String message1 = "{\"jsonrpc\" : \"2.0\", \"id\": 1, \"method\": \"mining.subscribe\", \"params\": []}";

It should be:

 

String message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}";

answered Apr 7, 2022 by Aditya
• 7,680 points

Related Questions In Blockchain

0 votes
1 answer

Bitcoin pool mining using stratum

JSON string shouldn't have any spaces. So ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 26,740 points
1,018 views
0 votes
1 answer

What happen to the mining fee for the blocks that are stale?

As I understood the forks of the ...READ MORE

answered Jun 4, 2018 in Blockchain by Shashank
• 10,400 points
492 views
0 votes
1 answer
0 votes
1 answer

How to add Bitcoin as currency for my website?

You cannot use BTC as the currency ...READ MORE

answered Aug 17, 2018 in Blockchain by slayer
• 29,350 points
831 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,144 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,691 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,232 views
0 votes
1 answer

Blockchain tutorials for double spending and signature verification

To answer your question, regardless of how ...READ MORE

answered Feb 24, 2022 in Blockchain by Aditya
• 7,680 points
506 views
0 votes
1 answer

BITCOIN TO USD API

You can use blockchain.info API: URL: https://blockchain.info/ticker Response: { "USD" : ...READ MORE

answered Apr 6, 2022 in Blockchain by Aditya
• 7,680 points
453 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP