0

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?

1 Answer 1

0

Fixed it with this code:

Buffer.from(utxoToCore(data).to_bytes()).toString("hex")

Data example:

  txHash: "5537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a87",
  outputIndex: 0,
  assets: { lovelace: 5000000 },
  address:
    "addr1q940ngxjex6me6yen0ryxr453apy8xdh8u8vc9plgr5v4jymzvxvxxv2sk2gvtlzthenrjmeg3esfhx5jufvs6p5lhcsak86ux",
};```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.