Skip to main content

Call a contract

Archetype provides a high-level instruction to call another contract.

8-1-contract_called.arl
archetype contract_called

variable n : nat = 0

entry set_n(p : nat) {
n := p
}

The caller contract uses the transfer instruction to call the get_n entry point. The address of the called contract is passed as parameter:

8-2-contract_caller.arl
archetype contract_caller

variable r : nat = 42

entry set_n(addr : address) {
transfer 0tz to addr call set_n<nat>(r)
}

A detailed presentation of the transfer instruction may be found here.

Deploy

The following Completium CLI commands deploy the contract on the Tezos network:

completium-cli deploy 8-1-contract_called.arl
completium-cli deploy 8-2-contract_caller.arl

Call caller's entry point

The following command calls the unique entry point:

completium-cli call 8-2-contract_caller --entry set_n --arg "{\"addr\": \"`completium-cli show address 8-1-contract_called`\"}"

Check called contract's storage

Check that called contract storage is now 42:

completium-cli show storage 8-1-contract_called