Serialization error with custom parameters

Please see the code below

from app.tsx

const params = {
credential_info: {
valid_from: “2023-08-24T12:00:00+05:00”,
valid_until: {“None”: },
holder_revocable: true,
holder_id: “c9762a4d5ba0ac17e4190428e140d897f4012ed4c4d0780064ebb780a7a46abb”,
metadata_url:{
url: “”,
hash: {“None”: }
},
“auxiliary_data”: [44]
}
};
// let params1 = “{ a:1 }”
// const params2 = Buffer.from(params);
const updateParams = serializeUpdateContractParameters(
contractName,
‘registerCredential’,
params,
rawModuleSchema
);

With contract entry points being following

/// Parameters for registering a credential
#[derive(Serialize, SchemaType, Clone, Debug)]
pub struct RegisterCredentialParam {
/// Public credential data.
credential_info: CredentialInfo,
/// Any additional data required by the issuer in the registration process.
/// This data is not used in this contract. However, it is part of the CIS-4
/// standard that this contract implements; auxiliary_data can be
/// used, for example, to implement signature-based authentication.
#[concordium(size_length = 2)]
auxiliary_data: Vec,
}

#[derive(Serialize, SchemaType, PartialEq, Eq, Clone, Debug)]
pub struct CredentialInfo {
/// The holder’s identifier is a public key.
holder_id: CredentialHolderId,
/// If this flag is set to true the holder can send a signed message to
/// revoke their credential.
holder_revocable: bool,
/// The date from which the credential is considered valid.
valid_from: Timestamp,
/// After this date, the credential becomes expired. None corresponds to a
/// credential that cannot expire.
valid_until: Option,
/// Link to the metadata of this credential.
metadata_url: MetadataUrl,
}

The error being received is following

test-contract-v2@1.0.0 start
tsc && node dist/app.js

Express is listening at http://localhost:3000
string
/home/yasir/concordium_dev/dapps/test-contract-v2/node_modules/@concordium/rust-bindings/pkg/node/concordium_rust_bindings.js:1409
const ret = new Error(getStringFromWasm0(arg0, arg1));
^

Error: Unable to serialize parameters, due to: “credential_info” → Too many fields provided
at module.exports.__wbindgen_error_new (/home/yasir/concordium_dev/dapps/test-contract-v2/node_modules/@concordium/rust-bindings/pkg/node/concordium_rust_bindings.js:1409:17)
at wasm://wasm/00748e9a:wasm-function[1054]:0x15c788
at module.exports.serializeReceiveContractParameters (/home/yasir/concordium_dev/dapps/test-contract-v2/node_modules/@concordium/rust-bindings/pkg/node/concordium_rust_bindings.js:511:14)
at serializeUpdateContractParameters (/home/yasir/concordium_dev/dapps/test-contract-v2/node_modules/@concordium/common-sdk/lib/serialization.js:323:39)
at testContract (file:///home/yasir/concordium_dev/dapps/test-contract-v2/dist/app.js:50:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The goal is to invoke the contract with custom parameters, I can invoke the contract with parameters provided above using cli, however with Node (typescript) I am receiving following error.

If you are using the contract example we have then auxiliaryData is not part of credential_info, so it should be

{
    credential_info: {
        valid_from: "2023-08-24T12:00:00+05:00",
        valid_until: {"None": []},
        holder_revocable: true,
        holder_id: "c9762a4d5ba0ac17e4190428e140d897f4012ed4c4d0780064ebb780a7a46abb",
        metadata_url:{
            url: "",
            hash: {"None": []}
        }
    }
    "auxiliary_data": [44]
}

Thx, however, I recieve following feedback

Transaction submitted, waiting for finalization…
{
blockHash: ‘35a9e1cebc2bebaab2407a920596bd7b305533c74284f8c299cc3ae28925c13c’,
summary: {
index: 0n,
energyCost: 1676n,
hash: ‘be5be6343155129b23b684f88c4e596bfde72a1bbc899e1a555ea153778bd607’,
type: ‘accountTransaction’,
cost: 6286737n,
sender: ‘3SfHLNkmy61ZUQkAhMvAwKj47EYDBiUPbn3wHghFD6qGr8WDGc’,
transactionType: ‘failed’,
failedTransactionType: ‘update’,
rejectReason: {
tag: ‘RejectedReceive’,
contractAddress: { index: 5979n, subindex: 0n },
receiveName: ‘hash_reg.credentialEntry’,
rejectReason: -2,
parameter: ‘c9762a4d5ba0ac17e4190428e140d897f4012ed4c4d0780064ebb780a7a46abb0180c157268a0100000000000001002c’
}
}
}

If I understand this means the transaction failed, however, I cannot comprehend the reason

You are calling credentialEntry function (which is a view function, so you really should not be sending a transaction to get the data, you should use the InvokeInstance entrypoint for this).

The error is telling you that the credential you are looking up does not exist.

I changed the entry to registerCrediential and recieved following response

Transaction submitted, waiting for finalization…
{
blockHash: ‘792f9ade703aa3cdd44afd6828db7bbe0f6c2e1cb2bc88e918ca68b76d0131b9’,
summary: {
index: 0n,
energyCost: 2316n,
hash: ‘19c5ac32f823ea5305d1b56193aca837d599915e301f8b779f45141c2f6fb8e6’,
type: ‘accountTransaction’,
cost: 8688313n,
sender: ‘3SfHLNkmy61ZUQkAhMvAwKj47EYDBiUPbn3wHghFD6qGr8WDGc’,
transactionType: ‘update’,
events: [
{
tag: ‘Updated’,
contractVersion: 1,
address: { index: 5979n, subindex: 0n },
instigator: {
type: ‘AddressAccount’,
address: ‘3SfHLNkmy61ZUQkAhMvAwKj47EYDBiUPbn3wHghFD6qGr8WDGc’
},
amount: 0n,
message: ‘c9762a4d5ba0ac17e4190428e140d897f4012ed4c4d0780064ebb780a7a46abb0180c157268a0100000000000001002c’,
receiveName: ‘hash_reg.registerCredential’,
events: []
}
]
}
}

Does this mean its successful and if so has it been registered against following?

hash: ‘19c5ac32f823ea5305d1b56193aca837d599915e301f8b779f45141c2f6fb8e6’,

Yes, your credential was registered. :slight_smile:

1 Like