Expected Behavior
When calling getPrefundedSpecializedBalanceWithProofInfo from the JS Evo SDK, the response is missing the data property when the identity has no prefunded balance. The response only contains proof and metadata, but no data key. Expected response:
{
"data": { ... },
"proof": { ... },
"metadata": { ... }
}
Current Behavior
Actual response:
{
"proof": { ... },
"metadata": { ... }
}
Possible Solution
Not sure. Claude's analysis doesn't seem right, since v2 of the SDK returns data for the same identity
Details
The issue may be in how `JsValue::UNDEFINED` is handled during JSON serialization in `ProofMetadataResponseWasm`.
Code flow:
packages/wasm-sdk/src/queries/system.rs:997-1004 - When no prefunded balance exists, data is set to JsValue::UNDEFINED
packages/wasm-sdk/src/queries/mod.rs:239-245 - to_serde() calls js_value_to_json(&self.data)
packages/wasm-dpp2/src/serialization/conversions.rs:77-86 - JsValue::UNDEFINED passes through as-is
- The
serde_wasm_bindgen::from_value() conversion of undefined produces a value that gets stripped during JSON serialization
In JavaScript/JSON, undefined is not a valid JSON value and gets stripped when serializing objects.
Comparison with Other Queries
Other proof-returning queries like getDataContractWithProofInfo return an error when the entity doesn't exist, rather than returning a response with undefined data. This inconsistency causes the issue.
Proposed Fix Options
Option A: Convert undefined to null in js_value_to_json function:
```rust
// In conversions.rs
if value.is_undefined() {
return Ok(JsValue::NULL);
}
```
Option B: Change the query to use JsValue::NULL instead of JsValue::UNDEFINED:
```rust
// In system.rs
.unwrap_or(JsValue::NULL) // Instead of JsValue::UNDEFINED
```
Option C: Return an error when no balance exists (consistent with getDataContract behavior).
Affected Files
packages/wasm-dpp2/src/serialization/conversions.rs
packages/wasm-sdk/src/queries/system.rs
Steps to Reproduce (for bugs)
- Request prefundedspecializedbalance with proofs via SDK for
AzaU7zqCT7X1kxh8yWxkT9PxAgNqWDu4Gz13emwcRyAT
Context
Previous version of the SDK (2.1.3) returned properly:
{
"data": {
"identityId": "AzaU7zqCT7X1kxh8yWxkT9PxAgNqWDu4Gz13emwcRyAT",
"balance": 0
},
"metadata": {
"height": 244622,
"coreChainLockedHeight": 1401324,
"epoch": 13049,
"timeMs": 1768329723380,
"protocolVersion": 10,
"chainId": "dash-testnet-51"
},
"proof": {
"grovedbProof": "AN0BoCIM+Mzx8hjU2wboZ+gyGBSBP1WhWq36bYEAEfDLWMYCz8MYPvG7yj2/ONc1zgkh5MbxTA6IlACRhZjm1WXhLAUQBAEoAA4EAQGA/QAAAAlQL5AAAGTF46wFRMs1FU5tX1URPPPBD/TROyQAedGr+SitkEYzAhOaTUYV+h6rV2C+AlogiYmKiLnXdDsMGV9O+CrZ+j8iEBECsw2pUsmJQ/480mGQAZ3YRg2IttAFEqWRU8nEZ4AgVqAQAa9X9pihRQAai3l0pM9CwaR5WCaEMfHtjG5HMVH2CJKdEQEBKFIEAYAALQQBIN9IMgDuv/EbWCUgx+9/XbdYgtmaXl9XIvVfy6Na5pj1/QAAAAlQL5AAAKSWRfATD8tQJDYz8ZOnuwXto1Xok5vvEgPziwTk1tbwAQGAQgUg30gyAO6/8RtYJSDH739dt1iC2ZpeX1ci9V/Lo1rmmPVBGmOtAutr7olPwCxNFoG7QN8wxUQyfjyXGp/yKNG0CAAB",
"quorumHash": "00000068e58c92f31089c245e7ee0076ba52e3b0f5a6d1379a3393dec220d89d",
"signature": "oK5jVyqwtW0RTdlPm4StNCGHCqVbO+h9QzTTIX2On9Zce7e+O6DerwpwuEVDAwF1BTg+JuyUmuxSr8IisYQNMtWGZxDIJO8RUaBbmb25Jb+g+lDyoZH+KZJeLbpWwkI5",
"round": 0,
"blockIdHash": "41c40febcf554988a931489169a6001a4a8c904467c0ff2d9faa879cee7f03b0",
"quorumType": 6
}
}
Your Environment
- Version used: SDK v3.0-rc.1 via evo-sdk-website
- Environment name and version (e.g. Chrome 39, node.js 5.4):
- Operating System and version (desktop, server, or mobile):
- Link to your project:
Expected Behavior
When calling getPrefundedSpecializedBalanceWithProofInfo from the JS Evo SDK, the response is missing the data property when the identity has no prefunded balance. The response only contains proof and metadata, but no data key. Expected response:
{
"data": { ... },
"proof": { ... },
"metadata": { ... }
}
Current Behavior
Actual response:
{
"proof": { ... },
"metadata": { ... }
}
Possible Solution
Not sure. Claude's analysis doesn't seem right, since v2 of the SDK returns data for the same identity
Details
The issue may be in how `JsValue::UNDEFINED` is handled during JSON serialization in `ProofMetadataResponseWasm`.Code flow:
packages/wasm-sdk/src/queries/system.rs:997-1004- When no prefunded balance exists,datais set toJsValue::UNDEFINEDpackages/wasm-sdk/src/queries/mod.rs:239-245-to_serde()callsjs_value_to_json(&self.data)packages/wasm-dpp2/src/serialization/conversions.rs:77-86-JsValue::UNDEFINEDpasses through as-isserde_wasm_bindgen::from_value()conversion ofundefinedproduces a value that gets stripped during JSON serializationIn JavaScript/JSON,
undefinedis not a valid JSON value and gets stripped when serializing objects.Comparison with Other Queries
Other proof-returning queries like
getDataContractWithProofInforeturn an error when the entity doesn't exist, rather than returning a response with undefined data. This inconsistency causes the issue.Proposed Fix Options
Option A: Convert
undefinedtonullinjs_value_to_jsonfunction:```rust
// In conversions.rs
if value.is_undefined() {
return Ok(JsValue::NULL);
}
```
Option B: Change the query to use
JsValue::NULLinstead ofJsValue::UNDEFINED:```rust
// In system.rs
.unwrap_or(JsValue::NULL) // Instead of JsValue::UNDEFINED
```
Option C: Return an error when no balance exists (consistent with getDataContract behavior).
Affected Files
packages/wasm-dpp2/src/serialization/conversions.rspackages/wasm-sdk/src/queries/system.rsSteps to Reproduce (for bugs)
AzaU7zqCT7X1kxh8yWxkT9PxAgNqWDu4Gz13emwcRyATContext
Previous version of the SDK (2.1.3) returned properly:
Your Environment