I deployed a voting contract and the module reference is 30c01802c6e711be957f47b3b3884c476e1c8df311c8a8d2290184377d9d0d64 and named it voting.
Then I tried to initialize the contract using the following code:
App.jsx
const param = {
description: "test voting contact",
options: ["IN", "US", "DK"],
end_time: "2028-10-31T23:59:59Z",
};
const txnHash = await stIdentityRegistry
.init(
"30c01802c6e711be957f47b3b3884c476e1c8df311c8a8d2290184377d9d0d64",
"voting"
)
.init(connection, accountAddress, param)
.then(TransactionHash.fromHexString);
stIdentiityRegistry
init: (moduleReference, contractName) =>
new InitMethod(
ModuleReference.fromHexString(moduleReference),
ContractName.fromString(contractName),
"//8DAQAAAAYAAAB2b3RpbmcBABQAAwAAAAsAAABkZXNjcmlwdGlvbhYCBwAAAG9wdGlvbnMQAhYCCAAAAGVuZF90aW1lDQIAAAAJAAAAZ2V0X2NvdW50ARQAAQAAAAUAAAB0YWxseRICFgIEBAAAAHZvdGUEFgIVBAAAAAoAAABQYXJzZUVycm9yAgcAAABFeHBpcmVkAhYAAABJbnZhbGlkQ29udHJhY3RBZGRyZXNzAhMAAABJbnZhbGlkVm90aW5nT3B0aW9uAgA="
),
deserializeEvent: (event) => {
return ContractEvent.parseWithSchemaTypeBase64(event, eventSchemaBase64);
},
generic_contract
export class InitMethod<TIn> {
constructor(
public moduleRef: ModuleReference.Type,
public contractName: ContractName.Type,
public paramsSchemaBase64?: string,
public maxExecutionEnergy: Energy.Type = Energy.create(60000)
) {}
async init(
provider: WalletConnection,
account: AccountAddress.Type,
params?: TIn,
amount: CcdAmount.Type = CcdAmount.fromCcd(0)
) {
const schema: TypeSchema | undefined = this.paramsSchemaBase64
? ({
type: "TypeSchema",
value: Buffer.from(this.paramsSchemaBase64, "base64"),
} as TypeSchema)
: undefined;
return provider.signAndSendTransaction(
account.address,
AccountTransactionType.InitContract,
{
amount,
moduleRef: this.moduleRef,
initName: this.contractName,
maxContractExecutionEnergy: this.maxExecutionEnergy,
} as SendTransactionInitContractPayload,
params && schema
? {
parameters: params as SmartContractParameters,
schema,
}
: undefined
);
}
parseError: (value: RejectedInit) => string | undefined = (value) => {
return `Error Code: ${value.rejectReason}`;
};
}
I referred this code: concordium-node-sdk-js/examples/wallet-connection/contractupdate/src/ContractInvoker.tsx at 34427125c0ffb0455ae3b6bb0a73a7b3dd195b8d · Concordium/concordium-node-sdk-js · GitHub
When I run this, I encounter the following error:
Why is this error, and how can I fix it?