Hi, I have several questions with Cadence Tutorial - Hello World.
Q1.
Do I always need to use save function to store objects in storage? I thought I can store every objects in my contract and doing it by using save. But it can be a little bit hard work to save everything if thereβs many objects in my contract.
So Iβm wondering if itβs impossible to store objects in storage without save function, and why this process (use this function to save objects in storage) is designed in Cadence.
Q2.
What is difference with β@β and β&β?
I found β@β at acct.load<@HelloWorld.HelloAsset>
and β&β at helloCapability!.borrow<&HelloWorld.HelloAsset> account.link<&HelloWorld.HelloAsset>
I guess both mean PATH, and differences are made from the types of functions(such as load, link and borrow) used� Do I understand well?
Q3.
Why does tutorial use log function in prepare block? I thought prepare block is to get access by using AuthAccount and manage everything associated with storage (e.g. load, link function). And using execute block to βexecuteβ something like log.
Q1: Do I always need to use save function to store objects in storage?
I thought I can store every objects in my contract and doing it by using save. But it can be a little bit hard work to save everything if thereβs many objects in my contract.
You can declare fields in contracts, and as contract are stored in accounts, these fields are automatically stored in the account. You can still use the save function in a a contract.
In general, try to store large objects in separate storage paths.
The save function also allows storing data in the account without having any contracts deployed to it.
To make the usage and behaviour of resource types explicit, the prefix @ must be used in type annotations of variable or constant declarations, parameters, and return types.
Q3. Why does tutorial use log function in prepare block?
The log function is used in the prepare block just as an example, to show that the prepare block is executed. The log function can be used anywhere for debugging purposes, and is not essential / required.