<p>The <code>getwork</code> RPC call was removed from Bitcoin Core. It was deprecated and then superceded by the <code>getblocktemplate</code> RPC call.</p>

<hr>

<p>It looks like the pool that you are using uses an unspecified protocol. It's just a tcp connection where you are sending JSON formatted strings and receiving JSON formatted strings from the pool server. I figured this out by digging through <a href="https://github.com/xmrig/xmrig" rel="nofollow noreferrer">this mining software's</a> source code.</p>

CC BY-SA 3.0
2018-01-20T08:00:06.233Z
I tried that. no luck either. :( by the way I am connecting to a monero pool URL if you see.
user1223879
CC BY-SA 3.0
2018-01-20T16:49:59.257Z
You have to use whatever protocol the pool is using. They probably use stratum, not `getwork` or `getblocktemplate`.
Ava Chow
CC BY-SA 3.0
2018-01-20T17:11:58.253Z
looks like they use getblocktemplate from this link : https://getmonero.org/resources/developer-guides/daemon-rpc.html
user1223879
CC BY-SA 3.0
2018-01-20T17:17:39.860Z
That's not necessarily true. That link points to the official monero node software documentation. But that is not the same as the pool that you are using. They don't necessarily have that exposed to miners to connect to, they may (probably) use stratum which is run by a software external to the node.
Ava Chow
CC BY-SA 3.0
2018-01-20T17:39:02.463Z
ok. let me try to use stratum and update the post. Thanks for your suggestions:)
user1223879
CC BY-SA 3.0
2018-01-21T16:20:01.287Z
Thanks again for your analysis. Even i suspected this and I tried direct connection but could not read anything from the input stream. Please check the edited question section for the tcp code at the end.
user1223879
CC BY-SA 3.0
2018-01-19T18:58:56.340Z
2018-01-20T17:39:15.060Z
2018-01-20T17:39:15.060Z
Ava Chow
<p>Finally I found the right string to be passed to the pool.</p>

<pre><code>String message1 = "{\"id\":1,\"method\":\"getblocktemplate\",\"params\":[\"wallet_address\":\"&lt;wallet_address&gt;\", \"reserve_size\" : 60]}\n";

String authorizemessage = "{\"params\":{\"login\":\"&lt;wallet_address&gt;\", \"pass\":\"x\"}, \"id\": 2, \"method\": \"login\"}\n";
</code></pre>

<p>After that we can first authorize using the authorizemessage and later pass message1 through the OutputStream of the socket.    </p>

CC BY-SA 3.0
2018-01-22T18:33:32.100Z
2018-01-22T18:33:32.100Z
user1223879
<p>I was going through this post in stack exchange <a href="https://bitcoin.stackexchange.com/questions/3168/how-can-i-code-a-bitcoin-json-rpc-getwork-request-in-java/3203">How can I code a Bitcoin JSON-RPC “getwork” request in Java? </a> </p>

<p>I tried to write a simple snippet for just the getwork json rpc.</p>

<pre><code>public static void main(String[] args) throws Exception {

    String request = "{\"method\": \"getwork\", \"params\": [], \"id\":0}";
    URL url = new URL("http://de01.supportxmr.com:7777");

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    if (conn .getConnectTimeout() == 0)
        conn.setConnectTimeout(1000);
    if (conn.getReadTimeout() == 0)
        conn.setReadTimeout(1000);
    conn.setRequestMethod("POST");
    String encoded = Base64.getEncoder().encodeToString(("&lt;my_wallet_addr&gt;:x").getBytes(StandardCharsets.UTF_8));  //Java 8
    conn.setRequestProperty("Authorization", "Basic "+encoded);
    conn.setRequestProperty("Accept", "application/json");
    conn.setRequestProperty("Content-Type", "application/json");
    conn.setRequestProperty("Content-Length", Integer.toString(request.getBytes().length));
    conn.setRequestProperty("X-Mining-Extensions", "midstate");
    conn.setAllowUserInteraction(false);
    conn.setUseCaches(false);
    conn.setDoOutput(true);

    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeBytes(request);
    wr.close();

    InputStream is = conn.getInputStream();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    int len;
    byte[] buffer = new byte[4096];
    while ((len = is.read(buffer)) != -1) {
        bos.write(buffer, 0, len);
    }
    String content = bos.toString();
    is.close();

    System.out.println(content);

}
</code></pre>

<p>when I run this code, I get an error</p>

<pre><code>Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:789)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1536)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at org.litecoinpool.miner.Test.main(Test.java:42)
</code></pre>

<p>What am I missing here? Is stratum proxy necessary to be running on the machine? If so how do I specify the parameters to run in the java code?</p>

<p>I tried a direct TCP connection also to the server.</p>

<pre><code>public static void main(String[] args) throws Exception {
    String message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}";
    String authorizemessage = "{\"params\": [\"&lt;wallet_address&gt;\", \"x\"], \"id\": 2, \"method\": \"mining.authorize\"}";


    Socket soc = new Socket("de01.supportxmr.com", 7777);
    System.out.println("connected");
    OutputStream outputStream = soc.getOutputStream();
    outputStream.write(authorizemessage.getBytes());
    outputStream.flush();

    BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    JSONObject json = new JSONObject(in.readLine());

    System.out.println("json response: " + json.toString());

    outputStream.write(message1.getBytes());
    outputStream.flush();

    in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    json = new JSONObject(in.readLine());

    System.out.println("json response: " + json.toString());

}
</code></pre>

<p>but no luck again :( </p>

<miner-configuration><java><getwork>
Unable to execute getwork logic in java
user1223879
# Unable to execute getwork logic in java

(Asked by: username_0 on 2018-01-19)

I was going through this post in stack exchange [How can I code a Bitcoin JSON-RPC “getwork” request in Java?](https://bitcoin.stackexchange.com/questions/3168/how-can-i-code-a-bitcoin-json-rpc-getwork-request-in-java/3203)

I tried to write a simple snippet for just the getwork json rpc.

```
public static void main(String[] args) throws Exception {

    String request = "{\"method\": \"getwork\", \"params\": [], \"id\":0}";
    URL url = new URL("http://de01.supportxmr.com:7777");

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    if (conn .getConnectTimeout() == 0)
        conn.setConnectTimeout(1000);
    if (conn.getReadTimeout() == 0)
        conn.setReadTimeout(1000);
    conn.setRequestMethod("POST");
    String encoded = Base64.getEncoder().encodeToString(("<my_wallet_addr>:x").getBytes(StandardCharsets.UTF_8));  //Java 8
    conn.setRequestProperty("Authorization", "Basic "+encoded);
    conn.setRequestProperty("Accept", "application/json");
    conn.setRequestProperty("Content-Type", "application/json");
    conn.setRequestProperty("Content-Length", Integer.toString(request.getBytes().length));
    conn.setRequestProperty("X-Mining-Extensions", "midstate");
    conn.setAllowUserInteraction(false);
    conn.setUseCaches(false);
    conn.setDoOutput(true);

    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeBytes(request);
    wr.close();

    InputStream is = conn.getInputStream();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    int len;
    byte[] buffer = new byte[4096];
    while ((len = is.read(buffer)) != -1) {
        bos.write(buffer, 0, len);
    }
    String content = bos.toString();
    is.close();

    System.out.println(content);

}

```

when I run this code, I get an error

```
Exception in thread "main" java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:789)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1536)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at org.litecoinpool.miner.Test.main(Test.java:42)

```

What am I missing here? Is stratum proxy necessary to be running on the machine? If so how do I specify the parameters to run in the java code?

I tried a direct TCP connection also to the server.

```
public static void main(String[] args) throws Exception {
    String message1 = "{\"id\":1,\"method\":\"mining.subscribe\",\"params\":[]}";
    String authorizemessage = "{\"params\": [\"<wallet_address>\", \"x\"], \"id\": 2, \"method\": \"mining.authorize\"}";

    Socket soc = new Socket("de01.supportxmr.com", 7777);
    System.out.println("connected");
    OutputStream outputStream = soc.getOutputStream();
    outputStream.write(authorizemessage.getBytes());
    outputStream.flush();

    BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    JSONObject json = new JSONObject(in.readLine());

    System.out.println("json response: " + json.toString());

    outputStream.write(message1.getBytes());
    outputStream.flush();

    in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
    json = new JSONObject(in.readLine());

    System.out.println("json response: " + json.toString());

}

```

but no luck again :(

**Tags:** miner-configuration, java, getwork


---

## 2 answers

### Answer by username_1 on 2018-01-19. Score: 3

The `getwork` RPC call was removed from Bitcoin Core. It was deprecated and then superceded by the `getblocktemplate` RPC call.

---

It looks like the pool that you are using uses an unspecified protocol. It's just a tcp connection where you are sending JSON formatted strings and receiving JSON formatted strings from the pool server. I figured this out by digging through [this mining software's](https://github.com/xmrig/xmrig) source code.

> **Comments:**
> **username_0**: I tried that. no luck either. :( by the way I am connecting to a monero pool URL if you see.  
> **username_1**: You have to use whatever protocol the pool is using. They probably use stratum, not `getwork` or `getblocktemplate`.  
> **username_0**: looks like they use getblocktemplate from this link : https://getmonero.org/resources/developer-guides/daemon-rpc.html  
> **username_1**: That's not necessarily true. That link points to the official monero node software documentation. But that is not the same as the pool that you are using. They don't necessarily have that exposed to miners to connect to, they may (probably) use stratum which is run by a software external to the node.  
> **username_0**: ok. let me try to use stratum and update the post. Thanks for your suggestions:)  
> **username_0**: Thanks again for your analysis. Even i suspected this and I tried direct connection but could not read anything from the input stream. Please check the edited question section for the tcp code at the end.  

---

### Answer by username_0 on 2018-01-22. Score: 0

Finally I found the right string to be passed to the pool.

```
String message1 = "{\"id\":1,\"method\":\"getblocktemplate\",\"params\":[\"wallet_address\":\"<wallet_address>\", \"reserve_size\" : 60]}\n";

String authorizemessage = "{\"params\":{\"login\":\"<wallet_address>\", \"pass\":\"x\"}, \"id\": 2, \"method\": \"login\"}\n";

```

After that we can first authorize using the authorizemessage and later pass message1 through the OutputStream of the socket.


---

