node-electrum-client icon indicating copy to clipboard operation
node-electrum-client copied to clipboard

Bug: failed to get block hash <block hash>

Open redtigervn opened this issue 1 year ago • 1 comments

Hi there,

I've installed bitcoin node and electrs server on VPS. I write nodejs script to listen new transaction from specific addrs and I get this error when I use Electrum protocol method blockchain.scripthash.subscribe to subscribe scripthash. Then I use electrumClient.subscribe.on event to listen new tx. But I always get this error

Failed to get block: 0000000000000000000000b71ed0d9bec536d4fbbfa4da8dece0edb25324d11db0

This block hash has 66 characters instead of 64 characters. Anyone get this error?

I also delete electrs_db folder and sync data again but it doesn't help.

image

const crypto = require('crypto');
const ecc = require('tiny-secp256k1');
const bitcoin = require('bitcoinjs-lib');
bitcoin.initEccLib(ecc);

const script = bitcoin.address.toOutputScript('1GrwDkr33gT6LuumniYjKEGjTLhsL5kmqC');
const hash = crypto.createHash('sha256').update(script).digest();
const reversedHash = Buffer.from(hash.reverse());
cosnt scripthash = reversedHash.toString('hex');

electrumClient.blockchainScripthash_subscribe(scripthash).then((scripthash) => {              
    console.log(`Subscribed to updates for scripthash: ${scriptHash}`);
});

electrumClient.subscribe.on('blockchain.scripthash.subscribe', async (data) => {
    const [scripthash, status] = data;
    //receive a notification when the status of the script hash changes.
    //do something here....
});

redtigervn avatar Oct 29 '24 07:10 redtigervn

sounds like electrs problem. you better take it to their github repo

Overtorment avatar Oct 30 '24 10:10 Overtorment