<p>Got the answer via <a href="https://github.com/bitcoinjs/bitcoinjs-lib/issues/990" rel="nofollow noreferrer">github</a></p>

<pre><code>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'))
</code></pre>

<p>Note that -for some reason- Electrum uses the reverse scripthash</p>

CC BY-SA 4.0
2019-01-14T07:09:45.030Z
can you post the result of the output please?
knocte
CC BY-SA 4.0
2023-12-25T20:18:42.283Z
Ya, most things in bitcoin need to have big-endian/little-endian conversion
Donn Lee
CC BY-SA 3.0
2018-01-18T17:33:32.847Z
2018-01-18T17:33:32.847Z
youssef
<p>I need to interact with Electrum server API, in order to get UTXOs of a bech32 address.</p>

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

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

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

<pre><code>       {'priv': 'L8g5V8kFFeg2WbecahRSdobARbHz2w2STH9S8ePHVSY4fmia7Rsj',
        'pub': '03e9f948421aaa89415dc5f281a61b60dde12aae3181b3a76cd2d849b164fc6d0b',
        'address': 'bc1qqmpt7u5e9hfznljta5gnvhyvfd2kdd0r90hwue',
        'minikey': False,
        'txin_type': 'p2wpkh',
        'compressed': True,
        'addr_encoding': 'bech32',
        'scripthash': '1929acaaef3a208c715228e9f1ca0318e3a6b9394ab53c8d026137f847ecf97b'}
</code></pre>

<bitcoinjs>
ScriptHash from bitcoin address with BitcoinJS
youssef
# ScriptHash from bitcoin address with BitcoinJS

(Asked by: username_0 on 2018-01-15)

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'}

```

**Tags:** bitcoinjs


---

## 1 answers

### Answer by username_0 on 2018-01-18. Score: 2 | Accepted answer

Got the answer via [github](https://github.com/bitcoinjs/bitcoinjs-lib/issues/990)

```
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

> **Comments:**
> **username_1**: can you post the result of the output please?  
> **username_2**: Ya, most things in bitcoin need to have big-endian/little-endian conversion  

---

