I’m starting to create a Rust REST component that interfaces with my concordium smart contract.
I’ve checked the concordium-rust-sdk examples but I cannot find any example code that does an init and call a receive update function of a smart contract. Do you have something you can share that calls a smart contract: init, call a receive function with json string using the concordium-rust-sdk?
I may be able to get some hints from the cics2 code in the concordium-rust-sdk lib – i.e., the transfer and updateOperator (can’t find init call anywhere), but wonder if someone has a more straightforward example that can guide me? Thanks.
Depending on your needs, you might not need to pass in JSON data for the parameter. Instead, you could get the data via the URL parameters. In the example that I created, it might be something like http://example.com/update?weather=sunny.
However, if you want to pass in the JSON parameter, then you will need to do something like the following:
Create a data type for the parameter and derive SerdeDeserialize and Serial (from concordium-contracts-common) for it.
Get the JSON string
Either directly as a string,
or via a file, which is read to a string with fx std::fs::read_to_string
Deserialize the JSON into the data type with serde_json::from_str.
Serialize the data type to binary with concordium_contracts_common::to_bytes (or concordium_contracts_common::Serial::serial if you want to create the buffer yourself).
Create the Parameter type with the binary data. Fx with Parameter::from(the_bytes) as I do in the example.
Hi @Kasper
I managed to looked into this today. Got stuck in coming up with the keys.json. I finally figured out the format (i.e., the accountKeys) but I could not find a way to get the “signKey”. I can only get the encryptedSignKey by running “config show”. Can you please help how I can convert this to a hex encoded signKey? Is there a tool I can use? I checked the wallet-notes README.md and there is a “get_account_keys_and_randomness” that can generate the signKey, but got 404s for the example jsons (input/output). Is this for the example.c and is this the tool to use to get the signing key? I have not tried compiling but I wonder if it will work on a Mac m1?
Essentially: download the linked tool, then run utils decrypt --in concordium-backup.concordiumwallet --out decrypted.json
The generated file decrypted.json will contain the data you need plus some additional data. Among other things, it contains a list of identities, and for each identity, there is a list of accounts created with that identity.
Find the account you are interested in using inside decrypted.json and extract the address and accountKeys fields to a new file, fx keys.json: