0

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))

2 Answers 2

2

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')
0

Try this one: utxo.input().transaction_id()

1
  • 1
    Close enough. Only thing left is to load bytes into Buffer and convert it to hex string.
    – pyropy
    Commented Dec 13, 2021 at 10:56

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.