Note: The library does not have implementations of all Electrum RPC resources[WIP]. PRs for new resources and endpoints are welcome, or you can simply implement some yourself as-you-go.
1. Install Electrum and create a wallet
By default, it's random port - set it to any port you want
./run_electrum setconfig rpcport 7777
./run_electrum setconfig rpcuser user
./run_electrum setconfig rpcpassword password
./run_electrum daemon start
If you want to start in testnet mode
./run_electrum --testnet daemon start
./run_electrum daemon load_wallet
If daemon is running in testnet, you need to specify to load testnet wallet
./run_electrum --testnet daemon load_wallet
Now you have a local Electrum JSON RPC server running - congrats 🥳
If you need to stop it, use
./run_electrum daemon stop
or if running in testnet
./run_electrum --testnet daemon stop
go get github.com/MarinX/electrumrpc
import "github.com/MarinX/electrumrpc"
You can find more in electrumrpc_test.go
// httpClient is optional
// if nil, the http.DefaultClient will be used
client := electrumrpc.New("<rpc-user>", "<rpc-password>", "<rpc-endpoint>", nil)
// Call RPC methods
ver, err := client.Version()
if err != nil {
//handle error
panic(err)
}
fmt.Println("Electrum version:", ver)
Not all endpoints are implemented right now. In those case, you can use Call method and point your model
var rpcResponse string
err := client.Call("version", nil, &rpcResponse)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Electrum version:", rpcResponse)
RPC Method | Available |
---|---|
version | ✅ |
getaddressbalance | ✅ |
getbalance | ✅ |
validateaddress | ✅ |
getservers | ✅ |
createnewaddress | ✅ |
getunusedaddress | ✅ |
ismine | ✅ |
gettransaction | ✅ |
getseed | ✅ |
listaddresses | ✅ |
addrequest | ✅ |
rmrequest | ✅ |
clearrequests | ✅ |
getrequest | ✅ |
getfeerate | ✅ |
signmessage | ✅ |
verifymessage | ✅ |
PR's are welcome. Please read CONTRIBUTING.md for more info
MIT