2

I'm trying to connect to an ElectrumX server from an HTML webpage. But I can't get a working connection.

I've tried with many servers from Electrum's servers.json list but none worked.

Here's the JavaScript code that I tried:

const socket = new WebSocket("ws://electrum.blockstream.info:50002");

// Connection opened
socket.addEventListener("open", () => {
  console.log("Connection opened");
});

socket.addEventListener("close", () => {
  console.log("Connection closed");
});

socket.addEventListener("error", e => {
  console.log("error", e);
});

socket.addEventListener("message", function(event) {
  console.log("Message from server ", event.data);
});

I tried both encrypted (wss) and non-encrypted (ws) connection. I tried several servers and different ports. I couldn't get it to connect.

Could someone share a working example of JavaScript code connecting to ElectrumX using WebSockets?

M.K. Safi
  • 143
  • 6
  • If I recall, electrum doesn't use wss (which is really https, right?) it uses raw SSL. So there's no usual header, just raw packets encrypted by SSL – pinhead Jul 27 '20 at 14:35
  • 1
    @pinhead according to the docs, it supports WebSockets, see https://electrumx.readthedocs.io/en/latest/environment.html#services – M.K. Safi Jul 27 '20 at 17:56
  • Ah you are right, it's the Electrum GUI that is raw SSL only (as of maybe a year ago when I last looked into it) – pinhead Jul 28 '20 at 11:46

0 Answers0