Skip to content

Send server.version as first message to interact with Electrumx server#504

Open
worldwideward wants to merge 1 commit into
1200wd:masterfrom
worldwideward:electrum-server-version
Open

Send server.version as first message to interact with Electrumx server#504
worldwideward wants to merge 1 commit into
1200wd:masterfrom
worldwideward:electrum-server-version

Conversation

@worldwideward
Copy link
Copy Markdown

We are using bitcoinlib for our project.

I had installed up a bitcoin-core node + electrumx server, locally in regtest mode.
I had configured bitcoinlib's provider.json to connect to the electrumx server

However, when executing wallet.scan(), bitcoinlib would throw an error:

2026/04/17 17:39:18 DEBUG _provider_execute(221) Error Extra data: line 2 column 1 (char 1024) on provider bitcoin.electrumx
2026/04/17 17:39:18 ERROR __init__(40) No successful response from any serviceprovider: ['bitcoin.electrumx']

The electrumx server complained:

INFO:ElectrumX:[3] TCP 172.20.0.12:42954, 1 total
INFO:ElectrumX:[3] closing session: server.version must be first msg. got: blockchain.headers.subscribe

After reading the protocol docs (https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-version) it became clear the electrumx provider in bitcoinlib wasn't sending this required message.

I could see the second message being crafted:

# bitcoinlib/services/electrumx.py
    def blockcount(self):
        return self.compose_request('blockchain.headers.subscribe')['height']

I realized that before sending blockcount() or other methods, the server.version message should be sent. But I wasn't completely sure how to implement this. As a last resort I shared the codebase with an AI model from Mistral, and asked for help. The result is this PR.

I am happy because now electrumx responds the way I expect it to:

2026/04/17 17:45:51 DEBUG _provider_execute(210) Executed method blockcount from provider bitcoin.electrumx
2026/04/17 17:45:51 DEBUG _provider_execute(210) Executed method getutxos from provider bitcoin.electrumx
2026/04/17 17:45:51 INFO utxos_update(3323) Got 0 new UTXOs for account 0
2026/04/17 17:45:52 INFO _balance_update(3152) Got balance for 10 key(s)

Now, if there is feedback on the implementation it is certainly welcome! But hopefully this can get merged 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant