Hello,
I am trying to pass parameter in ode using following service
export async function invokeSmartContract(contractAddress: number, entrypoint: string, param: String) {
// console.log(param.toString())
const invoker = AccountAddress.fromBase58('3SfHLNkmy61ZUQkAhMvAwKj47EYDBiUPbn3wHghFD6qGr8WDGc');
const contract = ContractAddress.create(contractAddress);
const receiveName = ReceiveName.fromString("cis2_dynamic_nft."+entrypoint);
const energy = Energy.create(30000);
const amount = CcdAmount.fromCcd(0)
let test = '{"key": "value"}';
let parameter;
try {
parameter = Parameter.fromJSON(test);
} catch(error) {
console.log(error)
}
console.log(parameter)
const context: ContractContext = {
// Required
method: receiveName,
contract,
// Optional
invoker,
amount,
parameter,
energy,
};
// console.log(param)
// const result = await client.invokeContract(context);
let result:any;
try {
result = await client.invokeContract(context);
// Handle the result as needed
} catch (error) {
console.error('Error invoking contract:', error);
// Handle the error as needed
}
console.log(result)
return result;
}
The error is following
{
tag: 'failure',
usedEnergy: Energy { value: 2207n, __type: 'ccd_energy' },
reason: {
tag: 'RejectedReceive',
contractAddress: ContractAddress {
index: 9583n,
subindex: 0n,
__type: 'ccd_contract_address'
},
receiveName: ReceiveName {
value: 'cis2_dynamic_nft.mint',
__type: 'ccd_receive_name'
},
rejectReason: -1,
parameter: Parameter { buffer: Uint8Array(0) [], __type: 'ccd_parameter' }
},
returnValue: ReturnValue {
buffer: Uint8Array(2) [ 3, 0 ],
__type: 'ccd_return_value'
}
}
The reason is that parameter is empty, I am trying to create parameter with following code
let test = '{"key": "value"}';
let parameter;
try {
parameter = Parameter.fromJSON(test);
} catch(error) {
console.log(error)
}
but its returning empty
Parameter { buffer: Uint8Array(0) [], __type: 'ccd_parameter' }
I have tried other methods as well .fromHextString but same result