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
- JS code calls
val.toJSON() on WASM objects for serialization
TokenContractInfoWasm has no toJSON() method (missing macro)
- Falls back to
Object.entries(val)
- wasm_bindgen getters aren't enumerable properties → returns
{}
Steps to Reproduce
- Use evo-sdk-website with SDK v3.0.0
- Select Queries > Token Queries > Get Token Contract Info
- Enter a valid token contract ID (e.g.,
H7FRpZJqZK933r9CzZMsCuf1BM34NT5P2wSJyjDkprqy on testnet)
- 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:
- Add
Serialize, Deserialize derives
- Add
#[serde(rename_all = "camelCase")]
- Add
impl_wasm_serde_conversions!(TokenContractInfoWasm, TokenContractInfo); macro
Or manually implement toJSON() method.