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,370 points
1,211 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
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Stratum connection for bitcoin pool mining

After hours of tinkering around I have ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
1,763 views
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,370 points
802 views
+1 vote
3 answers
+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,460 points
1,426 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,922 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,451 views
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
• 26,740 points
3,298 views
+1 vote
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
• 26,740 points
838 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