Skip to content

TokenContractInfoWasm missing toJSON() serialization - returns empty object #3027

@thephez

Description

@thephez

Description

getTokenContractInfo returns an empty object {} instead of the expected data like {"contractId": "...", "tokenContractPosition": 0}.

Root Cause

The TokenContractInfoWasm struct in packages/wasm-dpp2/src/tokens/contract_info.rs is missing serde serialization support.

Current code (broken):

#[wasm_bindgen(js_name = "TokenContractInfo")]
#[derive(Clone, Debug, PartialEq)]  // Missing Serialize, Deserialize
pub struct TokenContractInfoWasm(TokenContractInfo);
// Missing: impl_wasm_serde_conversions! macro

Compare to working types like TokenTotalSupplyWasm:

#[wasm_bindgen(js_name = "TokenTotalSupply")]
#[derive(Clone, Serialize, Deserialize)]  // Has serde derives
#[serde(rename_all = "camelCase")]
pub struct TokenTotalSupplyWasm { ... }

impl_wasm_serde_conversions!(TokenTotalSupplyWasm, TokenTotalSupply);  // Provides toJSON()

Why It Fails

  1. JS code calls val.toJSON() on WASM objects for serialization
  2. TokenContractInfoWasm has no toJSON() method (missing macro)
  3. Falls back to Object.entries(val)
  4. wasm_bindgen getters aren't enumerable properties → returns {}

Steps to Reproduce

  1. Use evo-sdk-website with SDK v3.0.0
  2. Select Queries > Token Queries > Get Token Contract Info
  3. Enter a valid token contract ID (e.g., H7FRpZJqZK933r9CzZMsCuf1BM34NT5P2wSJyjDkprqy on testnet)
  4. Execute - returns {} instead of contract info

Expected Behavior

Should return:

{
  "contractId": "EBioSoFFTDf346ndCMHGmYF8QzgwM8972jG5fL4ndBL7",
  "tokenContractPosition": 0
}

Suggested Fix

In packages/wasm-dpp2/src/tokens/contract_info.rs:

  1. Add Serialize, Deserialize derives
  2. Add #[serde(rename_all = "camelCase")]
  3. Add impl_wasm_serde_conversions!(TokenContractInfoWasm, TokenContractInfo); macro

Or manually implement toJSON() method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions