Bitcoin pool mining using stratum

0 votes

I have written a code to mine a pool using stratum protocol. The code is as follows:

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);

    }

}

I am supposed to get a response back but when I run this code, I don’t receive any response. What am I doing?

Aug 20, 2018 in Blockchain by slayer
• 29,050 points
31 views

1 answer to this question.

0 votes

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\":[]}";

When you make these change, it’ll work fine.

answered Aug 20, 2018 by digger
• 27,620 points

Related Questions In Blockchain

0 votes
1 answer

How to generate coin address using bitcoin-ruby?

The only difference between the addresses is ...READ MORE

answered Aug 29, 2018 in Blockchain by slayer
• 29,050 points
49 views
+1 vote
3 answers
0 votes
1 answer
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 ariaholic
• 7,320 points
56 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
104 views
0 votes
1 answer
0 votes
1 answer

Bitcoin: parsing Blockchain API using JSON

Because you only add one address to ...READ MORE

answered Aug 22, 2018 in Blockchain by digger
• 27,620 points
167 views
0 votes
1 answer

What is blockchain apart from bitcoin?

Blockchain is a decentralized database where the ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
12 views