Skip to content

cloneOutput helper function Map support #704

Description

@Daennes

Summary

The cloneOutput helper function currently uses JSON.stringify and JSON.parse to perform cloning. However, this approach does not support Map objects.
https://github.com/MeshJS/mesh/blob/main/packages/mesh-transaction/src/mesh-tx-builder/index.ts#L1799-L1801

As a result, when a Mesh Data object containing a Map is used as inline output data, the Map contents are lost during the cloning process.

Mesh Data Object can contain Maps
https://github.com/MeshJS/mesh/blob/main/packages/mesh-common/src/types/data.ts#L6

I encountered this issue when generating CIP68 metadata with metadataToCip68 and then using it in .txOutInlineDatumValue(cip68Metadatum, "Mesh") while creating a transaction.

Could be fixed with structuredClone

export const cloneOutput = (output: Output): Output => {
  return structuredClone(output);
};

Steps to reproduce the bug

No response

Actual Result

Empty Map and error in TX creation

Error:

Error: TypeError: Cannot convert undefined to a BigInt
    at BigInt (<anonymous>)
    at toPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4092:13)
    at .../node_modules/@meshsdk/core-cst/dist/index.js:4068:22
    at Array.forEach (<anonymous>)
    at toPlutusList (.../node_modules/@meshsdk/core-cst/dist/index.js:4067:11)
    at toPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4093:13)
    at fromBuilderToPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4167:12)
    at CardanoSDKSerializer.serializeOutput (.../node_modules/@meshsdk/core-cst/dist/index.js:6026:29)
    at getOutputMinLovelace (.../node_modules/@meshsdk/transaction/dist/index.js:5114:18)
    at _MeshTxBuilder.calculateMinLovelaceForOutput (.../node_modules/@meshsdk/transaction/dist/index.js:5028:12)

Expected Result

Non empty Map after clone and working TX

SDK version

1.9.0-beta.71

Environment type

  • Node.js
  • Browser
  • Browser Extension
  • Other

Environment details

No response

Activity

  1. added theissue type on Sep 2, 2025
  2. hinsoncode commented on Sep 2, 2025

    @hinsoncode
    Member

    @twwu123 please help check if its bug

  3. OscarOzaine commented on Jun 7, 2026

    @OscarOzaine

    Confirmed — this is a reproducible bug (cc @HinsonSIDAN @twwu123).

    Root cause is exactly as @Daennes described: cloneOutput uses a JSON round-trip, so a Map inside a Mesh Data inline datum (e.g. CIP-68 metadata from metadataToCip68) is cloned to an empty {}. Because cloneOutput runs inside getOutputMinLovelace, any build with a Map-bearing inline datum then fails in serializeOutput with Cannot convert undefined to a BigInt.

    I opened #831 with the suggested structuredClone fix plus regression tests (Map + bigint preserved, deep-copy independence, plain output unaffected). structuredClone also matches how the builder already clones txOutput in tx-builder-core.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions