0

I need to interact with Electrum server API, in order to get UTXOs of a bech32 address.

Electrum doesn't support bech32 but supports searching by ScriptHash, which is be obtainable from an address.

I think that the name ScriptHash is a little ambiguous here (i think locking script hash can make more sense)

So how can i get the scripthash from the address as in the following example using bitcoinjs :

       {'priv': 'L8g5V8kFFeg2WbecahRSdobARbHz2w2STH9S8ePHVSY4fmia7Rsj',
        'pub': '03e9f948421aaa89415dc5f281a61b60dde12aae3181b3a76cd2d849b164fc6d0b',
        'address': 'bc1qqmpt7u5e9hfznljta5gnvhyvfd2kdd0r90hwue',
        'minikey': False,
        'txin_type': 'p2wpkh',
        'compressed': True,
        'addr_encoding': 'bech32',
        'scripthash': '1929acaaef3a208c715228e9f1ca0318e3a6b9394ab53c8d026137f847ecf97b'}
1

Got the answer via github

let script = bitcoin.address.toOutputScript(address)
let hash = bitcoin.crypto.sha256(script)
let reversedHash = new Buffer(hash.reverse())

console.log(address, ' maps to ', reversedHash.toString('hex'))

Note that -for some reason- Electrum uses the reverse scripthash

  • can you post the result of the output please? – knocte Jan 14 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.