-1

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?

Geshode
  • 3,600
  • 6
  • 18
  • 32
Jan Swoboda
  • 152
  • 2
  • 15

1 Answers1

0

It looks like you are trying to call an external library. Usually, in such cases, it will return you a memory address. Just like you have it in wasm calls through browser client. One way is to deserialize your object inside your node js code.

Maybe you can use some sorta utility function to get it as a string.

E.g. https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/metadata.md#json-conversion

Hope this helps