Smart contract init failed with error coe

I have called my init function but when I try to call my_function I get the following error:

Receive function schema not found in contract schema

My code is like this:

#[derive(Debug, Serialize, SchemaType)]
pub struct ReceiveParams {
param1: Vec,
param2: String,
}

#[receive(
contract = “my_project”,
name = “contract_my_function”,
parameter = “ReceiveParams”,
error = “Error”,
mutable
)]
fn contract_my_function<S: HasStateApi>(
ctx: &impl HasReceiveContext,
host: &mut impl HasHost <State< S >, StateApiType = S>,
) - > Result<bool, Error> {

}

and I generate the schema by calling:
cargo concordium build --schema-base64-out -

Is there anything else I need to do to for the parameters to be seen?

Edit

Also, if I refactor the code and rename the function my_function rather than contract_my_function then the error message becomes:

Update contract failed:

No receive function 'my_function of contract ‘my_contract’ ’ found in module
67d568433bd72e4326241f262213d77f446db8ba03dfba351ae35c1b2e7e510

I am sure I read previously that the receive functions need to begin with ‘contract_’ but the examples I was looking at did not have that so I removed it. Do I need to put it back or is this a different issue?

  1. When using the contract you either have to embed the schema (using -e or --schema-embed) or you have to supply it to concordium-client. In that case you cannot use the base64 schema, but only the binary one.

  2. Receive function does not have to start with contract_. The --entrypoint argument in your case should be contract_my_function but I would recommned changing it to just my_function in the contracdt.

Thank you for your quick reply

1 - I was following the tutorial here tutorial where seemed to use the base64 schema and then supplied this to the dApp. Did I misunderstand?

I tried to embed the schema using --schema-embed and then rebuilt the wasm file and redeployed the contract but now I get the error “The given transaction is not valid due to: unable to deserialize parameters, due to: Unable to find contract schema in module schema” when I try to call the Init function. Do I need to change the webpage calling code as well?

2 - Sorry, I am not sure exactly what you mean:

Do you mean that I should do this:

#[receive(
contract = “my_project”,
name = “contract_my_function”,
parameter = “ReceiveParams”,
error = “Error”,
mutable
)]
fn contract_my_function<S: HasStateApi>(

Or this:

#[receive(
contract = “my_project”,
name = “contract_my_function”,
parameter = “ReceiveParams”,
error = “Error”,
mutable
)]
**fn my_function<**S: HasStateApi>(

  1. I meant
#[receive(
contract = “my_project”,
name = “my_function”,
parameter = “ReceiveParams”,
error = “Error”,
mutable
)]
**fn my_function<**S: HasStateApi>(

Re 1: Can you please provide a few more steps.

  • How exactly do you build.
  • How exactly are you deploying
  • How exactly are you sending a transaction.

Thank you.

Of course:

This is my build command:
cargo concordium build --out my_project.wasm.v1

This is my deploy command:
concordium-client module deploy my_project.wasm.v1 --sender my_account --name my_project --grpc-port 10000 --grpc-ip node.testnet.concordium.com

I use this to get the schema (as per the previously linked tutorial)
cargo concordium build --schema-base64-out -
I copy this and paste the output in to the front end code in the variable LP_RAW_SCHEMA

Transaction code in the front end is:

if (!connection || !account) return;
	connection.signAndSendTransaction(
		account,
		AccountTransactionType.Update,
		{
			amount: new CcdAmount(BigInt(0)),
			address: {
				index: BigInt(0),
				subindex: BigInt(0),
			},
			receiveName: `${CONTRACT_NAME}.my_function`,
			maxContractExecutionEnergy: MAX_CONTRACT_EXECUTION_ENERGY,
		},
		{
			vec_param: [],
			string_param: '00000001',
		},
		LP_RAW_SCHEMA,
	).then((result) => {
		console.log('result', result);
	}).catch((error) => {
		console.error('view error', error);
	});
}

Is there any way I can look at the deployed smart contract and see what functions it thinks it has?

Yes, you can use

concordium-client contract-show

Otherwise the commands look O assuming you update CONTRACT_NAME appropriately as well.

And of course if you update the address as well. The one you are showing is the contract instance at address (0,0) which is probably not your contract.

Thanks for the info.

I tried the command:

concordium-client module show project_name --out -

But I just get the error messge:
concordium-client.exe: user error (Cannot establish connection to GRPC endpoint.)

Is there some other setting somewhere I need?

The one you are showing is the contract instance at address (0,0) which is probably not your contract.
The output when I deployed said "Enter password for credential with index 0 and signing key with index 0: " and not done any updates or anything so I thought it would still be at 0,0.

Is that not right? If not, how do I determine which index it is at?

Update - I did some refactoring and now the init and receive functions both seem to link together from front end to back end.

However, my view function fails with:

unable to deserialize parameters, due to: Receive function schema does not contain a parameter schema

However, the function does not take any parameters and the return struct has the SchemType trait on it?

Any suggestions as to what might be wrong?

Update:

The init function works and can be called.
The receive function exists when looking at the smart contract on the chain but when called we get the error message that the function does not exist.

Anyone have any ideas on what might cause this?

Looks like this has been resolved

Thanks for the update.

Can you share what the issues were? Perhaps we can improve documentation if you found some things particularly confusing and they are not well explained in our existing documentation.

Of course.

I did not realise that the receive function had to be called with the index returned by the init function. When I added that in to the call from the front end connected.

My view function still fails with the error message “receive function schema does not contain a parameter schema”. However, it does not take any parameters and only returns a u32 wrapped in a ReceiveResult. The parameters schema is present for the contract through and the parameters for the other two functions are passed in correctly.

Which libraries are you using for making these queries?

There was a bug in the dapp-libraries where it wanted a schema even if it was not actually needed by the entrypoint.

Sorry, I should I have been more clear in my reply.

I have provided a schema, I built it because the init and receive functions have parameters and they all work. The view function is the only one that fails but that is the only one that has no parameters even though, in the dApp call, it has the schema.

Hi I’mm still getting the same error
unable to serialize parameters: parse error'

I’m sending CCD from wallet to contract through update function, its working from cli

Note: this function does not required parameter

There was a bug with an older version of the “dapp libraries” where it was not possible to invoke entrypoints that don’t take parameters. Have you updated to the latest version?

@abizjak updated version concordium-node-sdk ?

in this libarary also error I’ve created issue on github as well for that issue,

parseWallet is not exported

Github issue link