Error deserializing multiple UTXOs

When deserializing multiple UTXOs from the same wallet, in some point of the rawUtxos the process crash with this error. When doing the same process to deserialize the same UTXO but not on a loop, it works fine. Anyone maybe knows what could it be?

This is the typescript code that we use to deserialize, and the error is on the picture above

getUtxos= async () => {
    let Utxos = [];
    try {
        const rawUtxos = await this.API.getUtxos();
        for (const rawUtxo of rawUtxos) {
            const utxo = TransactionUnspentOutput.from_bytes(Buffer.from(rawUtxo, "hex"));
            const input = utxo.input();
            const txid = Buffer.from(input.transaction_id().to_bytes(), "utf8").toString("hex");
            const txindx = input.index();
            const output = utxo.output();
            const amount = output.amount().coin().to_str(); // ADA amount in lovelace
            const multiasset = output.amount().multiasset();
            let multiAssetStr = "";


            if (multiasset) {
                const keys = multiasset.keys() // policy Ids of thee multiasset
                const N = keys.len();
                // console.log(`${N} Multiassets in the UTXO`)


                for (let i = 0; i < N; i++){
                    const policyId = keys.get(i);
                    const policyIdHex = Buffer.from(policyId.to_bytes(), "utf8").toString("hex");
                    // console.log(`policyId: ${policyIdHex}`)
                    const assets = multiasset.get(policyId) as Assets
                    const assetNames = assets.keys();
                    const K = assetNames.len()
                    // console.log(`${K} Assets in the Multiasset`)

                    for (let j = 0; j < K; j++) {
                        const assetName = assetNames.get(j);
                        const assetNameString = Buffer.from(assetName.name(),"utf8").toString();
                        const assetNameHex = Buffer.from(assetName.name(),"utf8").toString("hex")
                        const multiassetAmt = multiasset.get_asset(policyId, assetName)
                        multiAssetStr += `+ ${multiassetAmt.to_str()} + ${policyIdHex}.${assetNameHex} (${assetNameString})`
                        // console.log(assetNameString)
                        // console.log(`Asset Name: ${assetNameHex}`)
                    }
                }
            }
            const obj = {
                txid: txid,
                txindx: txindx,
                amount: amount,
                str: `${txid} #${txindx} = ${amount}`,
                multiAssetStr: multiAssetStr,
                TransactionUnspentOutput: utxo
            }
            Utxos.push(obj);
            // console.log(`utxo: ${str}`)
        }
        this.state.Utxos = Utxos
        //this.setState({Utxos})
        console.log(Utxos)
    } catch (err) {
        console.log(err)
    }
  }

image

1 Like

Ran into the same issue using @emurgo/cardano-serialization-lib-asmjs, switching to @emurgo/cardano-serialization-lib-browser seemed to solve it.

Honestly, it seems that the Cardano StackExchange site may be a better place to ask this, or at least cross-post…