<p>In order to get transaction id using cardano-serialization-lib you should convert transaction id to bytes and convert them to hex string.</p>
<pre><code>Buffer.from(utxo.input().transaction_id().to_bytes()).toString('hex')
</code></pre>

CC BY-SA 4.0
2021-12-13T10:55:08.957Z
2021-12-13T10:55:08.957Z
pyropy
<p>Try this one: utxo.input().transaction_id()</p>

CC BY-SA 4.0
2021-12-13T10:56:09.037Z
Close enough. Only thing left is to load bytes into Buffer and convert it to hex string.
pyropy
CC BY-SA 4.0
2021-12-04T20:03:40.630Z
2021-12-04T20:03:40.630Z
Alicia Basilio
<p>I'm missing transaction prefix in order to get bech32 hash of transaction id using cardano-serialization-lib.</p>
<p>What prefix is used in transaction bech32 hash and how can I find/compute one?</p>
<pre><code>const decodeUtxo =
  (wasm: WasmT) =&gt;
  (encodedUtxo: string): WasmNamespace.TransactionUnspentOutput =&gt;
    wasm.TransactionUnspentOutput.from_bytes(Buffer.from(encodedUtxo, &quot;hex&quot;));

const collateralUtxos = (await wallet.getCollateral()).map(decodeUtxo(wasm));

const prefix = '' // how can I find this?

// to_bech32 function requires prefix
const collateralTxHashes = collateralUtxos.map((utxo) =&gt; utxo.input().transaction_id().to_bech32(prefix))
</code></pre>

<transaction><nami-wallet><cardano-serialization-lib><bech32>
How to get UTxO transaction id using cardano-serialization-lib
# How to get UTxO transaction id using cardano-serialization-lib

(Asked by: username_0 on 2021-12-03)

I'm missing transaction prefix in order to get bech32 hash of transaction id using cardano-serialization-lib.
What prefix is used in transaction bech32 hash and how can I find/compute one?
const decodeUtxo =
  (wasm: WasmT) =>
  (encodedUtxo: string): WasmNamespace.TransactionUnspentOutput =>
    wasm.TransactionUnspentOutput.from_bytes(Buffer.from(encodedUtxo, "hex"));

const collateralUtxos = (await wallet.getCollateral()).map(decodeUtxo(wasm));

const prefix = '' // how can I find this?

// to_bech32 function requires prefix
const collateralTxHashes = collateralUtxos.map((utxo) => utxo.input().transaction_id().to_bech32(prefix))

**Tags:** transaction, nami-wallet, cardano-serialization-lib, bech32

---

## 2 answers

### Answer by username_0 on 2021-12-13. Score: 2 | Accepted answer

In order to get transaction id using cardano-serialization-lib you should convert transaction id to bytes and convert them to hex string.
Buffer.from(utxo.input().transaction_id().to_bytes()).toString('hex')


---

### Answer by username_1 on 2021-12-04. Score: 0

Try this one: utxo.input().transaction\_id()

> **Comments:**
> **username_0**: Close enough. Only thing left is to load bytes into Buffer and convert it to hex string.  

---

