<p>Apparently you need to reverse the array before toString. <code>Transaction.ins[i].hash.reverse().toString('hex')</code> produces the correct result. Make sure to call hash.reverse() afterward.</p>

<p>source: <a href="https://bitcoin.stackexchange.com/questions/68565/scripthash-from-bitcoin-address-with-bitcoinjs">ScriptHash from bitcoin address with BitcoinJS</a></p>

CC BY-SA 4.0
2019-08-15T21:11:18.610Z
2019-08-15T22:27:41.630Z
2019-08-15T22:27:41.630Z
danosphere
<p>I'm using bitcoinjs-lib and its Transaction object. Transaction.ins is an array of objects, each which has a hash and script property. Both of these properties are Uint8Arrays. </p>

<p>I am trying to get the hex string version of the input.hash but Transaction.ins[i].hash.toString('hex') produces an incorrect result. Is there a way to get this value properly?</p>

<bitcoinjs>
How to get Bitcoin input transaction hash string from bitcoinjslib Transaction object?
danosphere
# How to get Bitcoin input transaction hash string from bitcoinjslib Transaction object?

(Asked by: username_0 on 2019-08-15)

I'm using bitcoinjs-lib and its Transaction object. Transaction.ins is an array of objects, each which has a hash and script property. Both of these properties are Uint8Arrays.

I am trying to get the hex string version of the input.hash but Transaction.ins[i].hash.toString('hex') produces an incorrect result. Is there a way to get this value properly?

**Tags:** bitcoinjs


---

## 1 answers

### Answer by username_0 on 2019-08-15. Score: 1

Apparently you need to reverse the array before toString. `Transaction.ins[i].hash.reverse().toString('hex')` produces the correct result. Make sure to call hash.reverse() afterward.

source: [ScriptHash from bitcoin address with BitcoinJS](https://bitcoin.stackexchange.com/questions/68565/scripthash-from-bitcoin-address-with-bitcoinjs)


---

