1
$ ./electrum-3.2.3.exe --testnet setconfig rpcport 7777
true
$ ./electrum-3.2.3.exe --testnet setconfig rpcuser blah
true
$ ./electrum-3.2.3.exe --testnet setconfig rpcpassword blah
true

$ ./electrum-3.2.3.exe --testnet daemon start
Traceback (most recent call last):
  File "run_electrum", line 433, in <module>
AttributeError: module 'os' has no attribute 'fork'

I can't install on linux as centos 7.5 can't compile python3. I won't try any further since I have already wasted a day on compilation issues.

$ ./electrum-3.2.3.exe --testnet

starts up a gui client which is fine

$ curl --data-binary '{"id":"curltext","method":"blockchain.scripthash.get_balance","params":["mveNDYcr9Bb1xjnNeCRumiDHKU3n3CJBuk"]}' http://blah:blah@127.0.0.1:7777
{"result": null, "id": "curltext", "error": {"code": -32601, "message": "Method blockchain.scripthash.get_balance not supported."}}
$ curl --data-binary '{"id":"curltext","method":"get_balance","params":["mveNDYcr9Bb1xjnNeCRumiDHKU3n3CJBuk"]}' http://blah:blah@127.0.0.1:7777
{"result": null, "id": "curltext", "error": {"code": -32601, "message": "Method get_balance not supported."}}
$ curl --data-binary '{"id":"curltext","method":"getbalance","params":["mveNDYcr9Bb1xjnNeCRumiDHKU3n3CJBuk"]}' http://blah:blah@127.0.0.1:7777
{"result": null, "id": "curltext", "error": {"code": -32601, "message": "Method getbalance not supported."}}

I also tried without specifying the bitcoin address with the same results.

https://bitcointalk.org/index.php?topic=1894185.0 discusses the same issue and states isnt giving an error about the wallet being loaded, which is why I am getting the error above. Assuming the poster didn't mean "isn't" but rather "is", how would I "unload the wallet"?

note: mveNDYcr9Bb1xjnNeCRumiDHKU3n3CJBuk is an address in electrum's wallet

  • try getaddressbalance. also electrum help on the command line on a linux system will show you some docs. – Abdussamad Oct 19 '18 at 0:17
0

Turns out that electrum doesn't have to be in daemon mode to receive api requests, but it has to be in daemon mode before it supports them.

0

OK so this is difficult. First you have to set up your Electrum "config" file (it doesn't have an extension) to make sure you can connect. You cannot use mine because it won't work but this is an example of mine. You have to add in "rpcport": XXXXX, with whatever port you want, make sure not to mess up the "," after each comment or Electrum will overwrite your file.

{

"auto_connect": true,
"config_version": 2,
"console-history": [],
"enable_opreturn": false,
"fee_per_kb": 1000,
"gui_last_wallet": "c:\\users\\xxx\\appdata\\roaming\\electroncash\\wallets\\default_wallet",
"is_maximized": false,
"recently_open": [
    "c:\\users\\xxx\\appdata\\roaming\\electroncash\\wallets\\default_wallet"
],
"rpcpassword": "5555555555555555==",
"rpcport": 54777,
"rpcuser": "user"

}

After you restart Electrum and log in using your password you can now connect using the code below. There are a few problems though. First, Electrum requires a wallet path, but you cannot specify the wallet path using code. This is some problem with linux I think they didn't add this functionality to windows. So the only way you can make sure your wallet is loaded is by the config file above where it says "recently_open" that has to point to your wallet you want to use. If you open the windows Electrum application and change wallets for some reason and then try to use this code below it won't work. Which is stupid but that's why people are having so much trouble with this.

There is a variable you can specify in "params" which is wallet_path but if you try to use it it won't work which is absolutely stupid, just fails so don't bother.

Thanks to this post: https://github.com/spesmilo/electrum/issues/5124 I was able to get mine to work but like I said the wallet_path doesn't work that's why those people where still having trouble.

In this example I'm using "getunusedaddress" instead of get wallet balance but they are both protected resources so you can just change between them.

import java.util.Base64;
import java.io.*;
import java.net.*;
import java.net.HttpURLConnection;


public class daemon_test {



    public static void main(String[] args) {

        String s1 = new String("default_wallet");

        //Set password 

        connect_daemon("{\"id\":\"myquery\",\"method\":\"daemon\",\"params\":{\"config_options\":{\"subcommand\":\"load_wallet\", \"password\":\"susdoimsa;df\"}}}");
        connect_daemon("{\"id\":\"myquery\",\"method\":\"help\"}");
        connect_daemon("{\"id\":\"myquery\",\"method\":\"getunusedaddress\"}");


    }



    public static String connect_daemon(String url_prams) {

        String responseh = new String("");

        try {

            String url = "http://127.0.0.1:54777";//<<<<<<<<<<< set the PORT you are using
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setReadTimeout(30000);

            //SET USER NAME >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
            String encoding = Base64.getEncoder().encodeToString("user:5555555555555555==".getBytes());

            //add reuqest header
            con.setRequestMethod("POST");
            con.setRequestProperty("Authorization", "Basic " + encoding);
            //con.setRequestProperty("method", "Basic " + encoding);

            String urlParameters = url_prams;//command=returnTradeHistory

            // Send post request
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();

            int responseCode = con.getResponseCode();
            //System.out.println("\nSending 'POST' request to URL : " + url);
            //System.out.println("Post parameters : " + urlParameters);
            //System.out.println("Response Code : " + responseCode);

            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            //BufferedReader in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            //print result
            System.out.println(response.toString());
            responseh = response.toString();

        }catch(Exception e){

            e.printStackTrace();
            responseh = e.getMessage();

        }//*****************

        return responseh;

    }

}

This is the output:

{"result": "qp0c59uccxftskajs5fxy2q7wn4cd03s9qzhlqfh4r", "id": "myquery","error": null}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.