Can a contract read another contract's storage?
No, not directly. However it is possible to call another contract with the
transfer instruction we have seen in previous examples.
It is then possible to setup a mechanism for a smart contract to retrieve a data from another smart contracts, under certain conditions and constraints:
- the smart contract you want to retrieve data from must provide an dedicated entry point to provide the data
- this entry point must accept an argument which is call-back to the calling contract; this call-back is an entry point to be called with the desired data as argument)
- the calling contract must provide a call-back entry point to handle the retreived data
It is indeed possible in Michelson to wrap an entrypoint address in a value and send it to an entry point with the
Archetype provides a high-level syntax for this pattern: the keyword
getter generates the required entry point and arguments.
The called contract provides a
getter entry point:
The caller contract uses a variation of the
transfer instruction to call the
get_n entry point. The address of the called contract is passed as parameter:
A detailed presentation of the
getter keyword may be found here.
The following Completium CLI commands deploy the contract on the Tezos network:
The following command calls the unique entry point:
You can retrieve the address of the called contract with this command: