Join Nostr
2026-06-26 06:05:09 UTC
in reply to

npub1yx…c399s on Nostr: This is pretty fun. Here's a suggestion: instead of relying only on esplora servers, ...

This is pretty fun. Here's a suggestion: instead of relying only on esplora servers, also give users an option connect to an electrum server via websockets instead. Here's some sample code to get you started:

List of electrum servers that accept websocket connections:

```
wss://btc.electroncash.dk:60004
wss://bitcoin.grey.pw:50004
wss://blackie.c3-soft.com:57004
wss://electrum.jochen-hoenicke.de:50010
wss://blockstream.info/electrum-websocket/
wss://mempool.guide/electrum-websocket/
```

Code for talking to them:

```
var socket = new WebSocket( 'wss://blockstream.info/electrum-websocket/' );
var formatted_command = {
"id": "test123",
"method": "blockchain.block.header",
"params": [ 101 ],
}
var handleFunction = async message => {
console.log( message.data );
}
socket.addEventListener( 'message', handleFunction );
socket.send( JSON.stringify( formatted_command ) );
```

List of useful methods:

```
blockchain.address.get_proof, [address]
blockchain.scripthash.get_balance, [scripthash]
blockchain.scripthash.get_history, [scripthash]
blockchain.scripthash.get_mempool, [scripthash]
blockchain.scripthash.listunspent, [scripthash]
blockchain.block.header, [height]
blockchain.block.headers, [start_height, count]
blockchain.estimatefee, [number]
blockchain.headers.subscribe, []
blockchain.transaction.broadcast, [rawtx]
blockchain.transaction.get, [tx_hash, verbose || false]
blockchain.transaction.get_merkle, [tx_hash, height]
```