Concordium / concordium-node-sdk-js

TypeScript SDK for using the Concordium blockchain
http://developer.concordium.software/concordium-node-sdk-js/
Apache License 2.0
20 stars 16 forks source link

Unable to serialize parameters, due to: Unable to find contract schema in module schema #224

Closed ash-hashtag closed 1 year ago

ash-hashtag commented 1 year ago

Bug Description

Parameters serialization fails with the error Unable to serialize parameters, due to: Unable to find contract schema in module schema

Steps to Reproduce

import {
    serializeUpdateContractParameters,
} from '@concordium/node-sdk';

const BALANCEOF_FUNCTION_RAW_SCHEMA = '//8CAQAAAAkAAABjaXMyX3dDQ0QBABQAAgAAAAMAAAB1cmwWAgQAAABoYXNoFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAAEyAAAAACAQAAAAkAAABiYWxhbmNlT2YGEAEUAAIAAAAIAAAAdG9rZW5faWQdAAcAAABhZGRyZXNzFQIAAAAHAAAAQWNjb3VudAEBAAAACwgAAABDb250cmFjdAEBAAAADBABGyUAAAAVBAAAAA4AAABJbnZhbGlkVG9rZW5JZAIRAAAASW5zdWZmaWNpZW50RnVuZHMCDAAAAFVuYXV0aG9yaXplZAIGAAAAQ3VzdG9tAQEAAAAVCQAAAAsAAABQYXJzZVBhcmFtcwIHAAAATG9nRnVsbAIMAAAATG9nTWFsZm9ybWVkAg4AAABDb250cmFjdFBhdXNlZAITAAAASW52b2tlQ29udHJhY3RFcnJvcgITAAAASW52b2tlVHJhbnNmZXJFcnJvcgIaAAAARmFpbGVkVXBncmFkZU1pc3NpbmdNb2R1bGUCHAAAAEZhaWxlZFVwZ3JhZGVNaXNzaW5nQ29udHJhY3QCJQAAAEZhaWxlZFVwZ3JhZGVVbnN1cHBvcnRlZE1vZHVsZVZlcnNpb24C';
const CONTRACT_NAME = 'cis2_wCCD';

const rawSchema = Buffer.from(BALANCEOF_FUNCTION_RAW_SCHEMA, "base64")
const param = serializeUpdateContractParameters(
        CONTRACT_NAME,
        'balanceOf',
        [
            {
                address: {
                    Account: [account],
                },
                token_id: '',
            },
        ],
        rawSchema,
    );

copied from https://github.com/Concordium/concordium-browser-wallet/blob/main/examples/wCCD/src/wCCD.tsx updateWCCDBalanceAccount function, and just changed toBuffer to node's Buffer.from

throws

Error: Unable to serialize parameters, due to: Unable to find contract schema in module schema
    at module.exports.__wbindgen_error_new (node_modules/@concordium/rust-bindings/pkg/node/concordium_rust_bindings.js:1348:17)
    at wasm://wasm/0065da26:wasm-function[899]:0x12d177
    at module.exports.serializeReceiveContractParameters (node_modules/@concordium/rust-bindings/pkg/node/concordium_rust_bindings.js:511:14)
    at serializeUpdateContractParameters (node_modules/@concordium/common-sdk/lib/serialization.js:323:39)

Expected Result To not throw error, and serialize as usual

Actual Result Throws error. Could anyone point out what I'm doing wrong?

Versions

soerenbf commented 1 year ago

The function you're trying to use takes the schema of a contract module, whereas the name of your schema constant indicates you specify the schema for a function (perhaps it's parameters?). If this assumption is correct, this will likely be why it fails.

If you want to use the schema for a functions parameters, please try using the function serializeTypeValue instead.

ash-hashtag commented 1 year ago

I didn't change anything, and it got fixed somehow now it works.