Interact#

This guide will show you, how to interact with a smart contract instance, which means triggering a receive function that, possibly, updates the state of the instance.

You can also watch a video about how to update a smart contact instance.

Preparation#

Make sure that you are running a node using the latest Concordium software and that you have a smart-contract instance on-chain to inspect.

See also

For how to deploy a smart contract module see Deploy a smart contract module and for how to create an instance Initialize.

Since interactions with a smart contract are transactions, you should also make sure to have concordium-client set up with an account with enough CCD to pay for the transactions.

Note

The cost of this transaction depends on the size of the parameters sent to the receive function and the complexity of the function itself.

Interaction#

To update an instance with address index 0 using the parameterless receive function my_receive while allowing up to 10000 energy to be used, run the following command:

$concordium-client contract update 0 --entrypoint my_receive --energy 10000 --sender MyAccount

If successful, the output should be similar to the following:

Successfully updated contract instance {"index":0,"subindex":0} using the entrypoint 'my_receive'.

As you can see, the subindex defaults to 0.

Passing parameters in JSON format#

A parameter in JSON format can be passed if a smart contract schema is supplied, either as a file or embedded in the module. The schema is used to serialize the JSON into binary. You can read more about JSON parameters here.

To update an instance with address index 0 using the receive function my_parameter_receive with a parameter file my_parameter.json in JSON format, run the following command:

$concordium-client contract update 0 --sender MyAccount --entrypoint my_parameter_receive \
         --energy 10000 \
         --parameter-json my_parameter.json

If successful, the output should be similar to the following:

Successfully updated contract instance {"index":0,"subindex":0} using the entrypoint 'my_parameter_receive'.

Otherwise, an error describing the problem is displayed.

See also

For more information about contract instance addresses, see References on-chain.

Note

If the parameter provided in JSON format does not conform to the type specified in the schema, an error message will be displayed. For example:

Error: Could not decode parameters from file 'my_parameter.json' as JSON:
Expected value of type "UInt64", but got: "hello".
In field 'first_field'.
In {
    "first_field": "hello",
    "second_field": 42
}.

Note

If a given module does not contain an embedded schema, it can be supplied using the --schema /path/to/schema.bin parameter.

Note

CCD can also be transferred to a contract during updates using the --amount AMOUNT parameter.

Passing parameters in binary format#

When passing parameters in binary format, a contract schema is not needed.

To update an instance with address index 0 using the receive function my_parameter_receive with a parameter file my_parameter.bin in binary format, run the following command:

$concordium-client contract update 0 --sender MyAccount --entrypoint my_parameter_receive \
         --energy 10000 \
         --parameter-binary my_parameter.bin

If successful, the output should be similar to the following:

Successfully updated contract instance {"index":0,"subindex":0} using the entrypoint 'my_parameter_receive'.

See also

For information on how to work with parameters in smart contracts, see Work with parameters.

Was this article helpful?