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 in Blockchain by Rahul
• 9,680 points
347 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 by Aditya
• 7,660 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,720 points
631 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
239 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,310 points
587 views
0 votes
1 answer

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

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
728 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,106 views
0 votes
1 answer
0 votes
1 answer

Blockchain tutorials for double spending and signature verification

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

answered Feb 24 in Blockchain by Aditya
• 7,660 points
228 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 in Blockchain by Aditya
• 7,660 points
110 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