node-electrum-client
node-electrum-client copied to clipboard
Bug: failed to get block hash <block hash>
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.
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....
});
sounds like electrs problem. you better take it to their github repo