Bitcoin Forum

Bitcoin => Electrum => Topic started by: drsnuggles on September 24, 2016, 06:18:48 PM



Title: Query Electrum from website via json-rpc: connection refused
Post by: drsnuggles on September 24, 2016, 06:18:48 PM
For a small webshop I want to enable bitcoin payments. Since the good old blockchain.info wallet doesn't support json-rpc anymore, I would like to use electrum.

I have electrum running on a raspberry pi successfully. Queries run wel locally. My website is on shared hosting somewhere else. I would like to query electron via stratum/json-rpc from the webserver. However, Electrum only accepts connections from localhost, not from 0.0.0.0,  according to netstat.

Two questions that pop up:
1. How can I configure Electrum to accept connections from outside?
2. How safe is opening up a port to the outside world? I want to use ip restrictions in my local router.  Further security would be using ssl, but ssl over json-rpc is not recommended. Ssh tunnels are not available on shared hosting either.


Title: Re: Query Electrum from website via json-rpc: connection refused
Post by: btcbot on September 25, 2016, 02:53:27 PM
Have you read this?

http://docs.electrum.org/en/latest/merchant.html


Title: Re: Query Electrum from website via json-rpc: connection refused
Post by: drsnuggles on September 25, 2016, 03:48:17 PM
Have you read this?

http://docs.electrum.org/en/latest/merchant.html
Thanks for the link  :).  I did indeed use it to set up Electrum. I can perform all the given curl queries locally without any problem. If however, instead of 127.0.0.1 I use its network address: 192.16.1.60 I get "connection refused".

This morning I tried to forward all traffic of port 7777 from 192.168.1.60 to 127.0.0.1, but I still get connction refused. I followed this post: http://unix.stackexchange.com/questions/111433/iptables-redirect-outside-requests-to-127-0-0-1  and probably did something wrong, since I am not a debian/raspbian expert.

Either I find a way to forward data correctly, or enable Electrum to listen to port 7777 on 192.168.1.60.


Title: Re: Query Electrum from website via json-rpc: connection refused
Post by: drsnuggles on September 25, 2016, 07:46:55 PM
Alright, found a workaround to forward data from 192.168.1.60 to 127.0.0.1.

Code:
sudo sysctl -w net.ipv4.conf.eth0.route_localnet=1
sudo iptables -t nat -I PREROUTING -p tcp -d 192.168.1.60/32 --dport 7777 -j DNAT --to-destination 127.0.0.1:7777


Important: to check the result, go to another pc and query:
Code:
 curl --data-binary '{"id":"curltext","method":"getbalance","params":[]}' http://192.168.1.60:7777


I checked on the same pc as Electrum runs, and apparently that doesn't work.

Next step is to secure the line :).