<p>Fixed it with this code:</p>
<p><code>Buffer.from(utxoToCore(data).to_bytes()).toString(&quot;hex&quot;)</code></p>
<p>Data example:</p>
<pre><code>  txHash: &quot;5537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a87&quot;,
  outputIndex: 0,
  assets: { lovelace: 5000000 },
  address:
    &quot;addr1q940ngxjex6me6yen0ryxr453apy8xdh8u8vc9plgr5v4jymzvxvxxv2sk2gvtlzthenrjmeg3esfhx5jufvs6p5lhcsak86ux&quot;,
};```
</code></pre>

CC BY-SA 4.0
2022-09-12T18:14:46.597Z
2022-09-12T18:14:46.597Z
Jan Swoboda
<p>So basically I want to convert a normal UTxO hash like:</p>
<p><code>550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3</code></p>
<p>to a TransactionUnspentOutput as a hex encoded bytes string like:</p>
<p><code>828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701</code></p>
<p>This is how it is done with a nami wallet implementation:</p>
<p><code>cardano.getUtxos(amount?: Value, paginate?: {page: number, limit: number}) : [TransactionUnspentOutput]</code></p>
<p>I tried to pass a UTxO into the lucid <code>utxoToCore()</code> function:</p>
<pre><code>export const utxoToCore = (utxo: UTxO): Core.TransactionUnspentOutput =&gt; {
  const output = C.TransactionOutput.new(
    C.Address.from_bech32(utxo.address),
    assetsToValue(utxo.assets)
  );
  if (utxo.datumHash) {
    output.set_datum(
      C.Datum.new_data_hash(C.DataHash.from_bytes(fromHex(utxo.datumHash)))
    );
  }
  return C.TransactionUnspentOutput.new(
    C.TransactionInput.new(
      C.TransactionHash.from_bytes(fromHex(utxo.txHash)),
      C.BigNum.from_str(utxo.outputIndex.toString())
    ),
    output
  );
};
</code></pre>
<p>However the only output I get is: <code>TransactionUnspentOutput { ptr: 1247376 }</code></p>
<p>How to get the unpacked (?), or at least the right format I want,  TransactionUnspentOutput?</p>
<pre><code></code></pre>

<cardano-serialization-lib><utxo><cardano-address>
How to get TransactionUnspentOutput as a hex encoded bytes string programmatically
# How to get TransactionUnspentOutput as a hex encoded bytes string programmatically

(Asked by: username_0 on 2022-09-09)

So basically I want to convert a normal UTxO hash like:
550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3
to a TransactionUnspentOutput as a hex encoded bytes string like:
828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701
This is how it is done with a nami wallet implementation:
cardano.getUtxos(amount?: Value, paginate?: {page: number, limit: number}) : [TransactionUnspentOutput]
I tried to pass a UTxO into the lucid utxoToCore() function:
export const utxoToCore = (utxo: UTxO): Core.TransactionUnspentOutput => {
  const output = C.TransactionOutput.new(
    C.Address.from_bech32(utxo.address),
    assetsToValue(utxo.assets)
  );
  if (utxo.datumHash) {
    output.set_datum(
      C.Datum.new_data_hash(C.DataHash.from_bytes(fromHex(utxo.datumHash)))
    );
  }
  return C.TransactionUnspentOutput.new(
    C.TransactionInput.new(
      C.TransactionHash.from_bytes(fromHex(utxo.txHash)),
      C.BigNum.from_str(utxo.outputIndex.toString())
    ),
    output
  );
};

However the only output I get is: TransactionUnspentOutput { ptr: 1247376 }
How to get the unpacked (?), or at least the right format I want,  TransactionUnspentOutput?

**Tags:** cardano-serialization-lib, utxo, cardano-address

---

## 1 answers

### Answer by username_0 on 2022-09-12. Score: 0 | Accepted answer

Fixed it with this code:
Buffer.from(utxoToCore(data).to_bytes()).toString("hex")
Data example:
  txHash: "5537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a87",
  outputIndex: 0,
  assets: { lovelace: 5000000 },
  address:
    "addr1q940ngxjex6me6yen0ryxr453apy8xdh8u8vc9plgr5v4jymzvxvxxv2sk2gvtlzthenrjmeg3esfhx5jufvs6p5lhcsak86ux",
};```


---

