2

I'm new to smart contracts and I'm having difficulty understanding the logic behind instantiating multi-index tables and how they persist.

For example in the addressbook example, it seems a new table is created every time an entry is made(or erased etc).. this doesn't make any sense and obviously something else is going on under the hood but it's not clear how it's all working? Thanks

1 Answer 1

1

For example in the addressbook example, it seems a new table is created every time an entry is made(or erased etc)..

This is correct. Whenever a node runs a transaction, it starts with a brand new working memory, so variables need to be recreated. However, multi-index tables are used to interface with the persistent EOSIO storage where data is stored between transactions in the memory of each node (also named RAM in EOSIO).

In other words, when you're using multi-index tables, you're communicating with an off-chain database that preserves the blockchain state.

This article on the EOSIO DB model may be helpful to read.

2
  • Ok. So the storage itself is automatically created? Is that automatic for each struct defined in a contract? Or each table defined in the abi? Or something similar? Sep 19, 2018 at 15:42
  • storage is created when you use it. it's not per struct; you don't need necessarily need structs. you need eosio::multi_index instances which may use structs
    – confused00
    Sep 19, 2018 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.