Skip to content

Latest commit

 

History

History
57 lines (36 loc) · 2.05 KB

jsonrpc.rst

File metadata and controls

57 lines (36 loc) · 2.05 KB

JSONRPC interface

Commands to the Electrum daemon can be sent using JSONRPC. This is useful if you want to use electrum in a PHP script.

Note that the daemon uses a random port number by default. In order to use a stable port number, you need to set the 'rpcport' configuration variable (and to restart the daemon):

electrum setconfig rpcport 7777

Further, starting with Electrum 3.0.5, the JSON-RPC interface is authenticated using HTTP basic auth.

The username and the password are config variables. When first started, Electrum will initialise both; the password will be set to a random string. You can of course change them afterwards (the same way as the port, and then restart the daemon). To simply look up their value:

electrum getconfig rpcuser
electrum getconfig rpcpassword

Note that HTTP basic auth sends the username and the password unencrypted as part of the request. While using it on localhost is fine in our opinion, using it across an untrusted LAN or the Internet is not secure. Hence, you should take further measures in such cases, such as wrapping the connection in a secure tunnel. For further details, read this.

After setting a static port, and configuring authentication, we can perform queries using curl or PHP. Example:

curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"getbalance","params":[]}' http://username:[email protected]:7777

Query with named parameters:

curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"listaddresses","params":{"funded":true}}' http://username:[email protected]:7777

Create a payment request:

curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"add_request","params":{"amount":"3.14","memo":"test"}}' http://username:[email protected]:7777