Interact with a smart contract instance#

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.

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 a smart contract instance.

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 1000 energy to be used, run the following command:

$concordium-client contract update 0 --func my_receive --energy 1000

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

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

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.

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 --func my_parameter_receive \
         --energy 1000 \
         --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 function 'my_parameter_receive'.

Otherwise, an error describing the problem is displayed. Common errors are described in the next section.

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 --func my_parameter_receive \
         --energy 1000 \
         --parameter-bin my_parameter.bin

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

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

See also

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

Was this article helpful?
Legal information