Getting error while calling the init from frontend

Hey guys, this is my contract initialization code:

Link to gist for contract init code

And this is how I am trying to initialize the contract:

Link to gist for initialization code

This command successfully initialized the contract from CLI:

concordium-client contract init 1c2b49f1455a56e0d4d9bcd69702eeb9c99096298c26f60b80917ebd80360f25 --schema dist/smart-contract-multi/schema.bin --sender 3uNL2SZA6RRy4avkFBALac4j5tiEzak99gWsj7HBfexmPApcTB --energy 30000 --contract cis2_multi --parameter-json params/initParams.json --grpc-ip node.testnet.concordium.com --grpc-port 20000

Initialization params:

{
  "hash": { "None": [] },
  "url": "https://maroon-increasing-dragonfly-570.mypinata.cloud/ipfs/QmR65wrnYMPEP1WKGJN1zjcibTxpUJbEW1M4bVMQdJw1gU"
}

However, when trying to initialize it from the frontend, I keep encountering this issue:

“Rejected due to contract logic in init function of a contract
Error code: -2147483646”

Please help me understand what I am doing wrong.

Note I have created the schema for web using this command

cargo concordium build --schema-base64-out “/some/path/base64_schema.b64”

And I took reference from this tutorial

https://academy.concordium.software/beginner-level-tutorials/simple-minting-dapp

Hi @subhajit

So it seems that you are parsing the schema as hex encoded, but it is actually base64 encoded.

Do this:

const contractSchema = Buffer.from(
    REACT_APP_CONTRACT_SCHEMA!,
    "base64"
   );

Also, consider using our tool ccd-js-gen for generating smart contract clients, most of the schema details would be done for you.

 const contractSchema = Buffer.from(
    REACT_APP_CONTRACT_SCHEMA!,
    "base64"
   );

Tried this one still getting the same error.
https://testnet.ccdscan.io/?dcount=1&dentity=transaction&dhash=4ef81e5639ff617eacb6a0bbf48164dcdd2480d59cbab4bb41637b4470a496a2

Could you please explain how you generated the value of “MULTI_CONTRACT_SCHEMA” in this tutorial? I used the base64 type, but I believe this is where I’m going wrong. Due to this, I’m unable to proceed with the tutorial.

I used the following command to generate the schema:

cargo concordium build --out dist/smart-contract-multi/module.wasm.v1 --schema-base64-out dist/smart-contract-multi/schema_base64.b64

According to Concordium’s documentation, this should output a schema file.

The tutorial seems a bit outdated, which version of the web-sdk are you using?
If you are using a relatively new version then serializeInitContractParameters takes a ContractName instead of a plain string.
You can convert it using:

ContractName.fromString(REACT_APP_CONTRACT_NAME)

To answer your question above:
The schema in that tutorial seems to be hex and not base64, which you can generate either from the base64 schema or from the binary representation of the output of --schema-out, but not directly using cargo concordium.
In the end it should be the same as using the base64 as long as you decode it correctly.

If you want to see the hex representation of the base64 schema, you can do this:

Buffer.from(REACT_APP_CONTRACT_SCHEMA, "base64").toString("hex")