Hello guys, I don't quite understand how the contract storage work, why I can just store the value in the contract using set_data without specifiying the name of the variable, what if I have more than 1 varibles need to store in the contract storage?
Also, when I am sening messageBody with cell data, can I just append unlimited number of storeUint in the cell?
Last but not least, is that anyway to kwon gas fee and ask users to pay for the transaction, cos unlike Ethereum, if users didn't pay enough gas, the transaction won't be done. But here on TON, the contract will pay the gas for computing.
Sep 21, 2023, 4:36 PM
1. Contract storage is cell.
2. Cell stores 0-1023 bits and 0-4 references to other cells.
3. When you use several store_uint-s, you fill the cell, and once there's no more space, writing will fail.
4. Gas fees are usually calculated approximately and offchain. Also, a common practice is to send more TONs and return the excess.
2. Cell stores 0-1023 bits and 0-4 references to other cells.
3. When you use several store_uint-s, you fill the cell, and once there's no more space, writing will fail.
4. Gas fees are usually calculated approximately and offchain. Also, a common practice is to send more TONs and return the excess.
Sep 21, 2023, 4:52 PM
thank you sir, please allow me to ask a follow up question, for example, I would like to store a list of registered addresses in the smart contract and the deposited balance of each of them, shd make a list of cells with each cell store the address and their balance and store the list using save_data? What if I need to store the list together with the total deposited balance, what should I do?
Sep 22, 2023, 2:29 AM
> store a list of registered addresses in the smart contract and the deposited balance of each of them
If there are more than 500 addresses, you should consider sharding the contract further. Otherwise, you can use dict.
begin_cell().store_dict(users).store_coins(total_balance).end_cell().set_data();
If there are more than 500 addresses, you should consider sharding the contract further. Otherwise, you can use dict.
begin_cell().store_dict(users).store_coins(total_balance).end_cell().set_data();
Sep 22, 2023, 2:30 AM
thank you so much
in this case, what if I have to dictionaries, so I will call store_dict tiwce, and it will follow the "last in first out" order when I need to get it back using get_data()?
Sep 22, 2023, 2:43 AM
*First in, first out. Slices allow reading from the beginning of the cell.
Sep 22, 2023, 2:44 AM
I see, may I know more about how to shard a contract. I am not able to find any related information on doc.ton.org.
Sep 22, 2023, 2:45 AM
https://blog.ton.org/how-to-shard-your-ton-smart-contract-and-why-studying-the-anatomy-of-tons-jettons
Sep 22, 2023, 2:46 AM
one more thing, why I should use store_dict() instead of just making a global dict or any kind of variables?
Sep 22, 2023, 2:47 AM
Because global variables are not saved across contract calls.
Sep 22, 2023, 2:48 AM
got it
thank you so much
Sep 22, 2023, 2:49 AM