Local State limitations

So, from docs we have:

And I was wondering if this means that, for example, if I have one variable stored in Local State to save the balance of an user in my smart contract, and then 100 users using my smart contract, in this scenario it will count as 1 key-pair value (the balance variable) for the 16 key-pair values limitation or this will count as 100 key-pair value (100 users using this balance variable)?

Can anyone clarify this for me?


Hi @vinivst,

Each time an Account opt-in a Smart Contract its Local State is allocated in the Account’s state table.

This means that you can have hundreds, thousands or millions Accounts opting-in the Smart Contract, for each one of those the Local State can handle up to 16 variables, stored as key/value pairs.

So, following your example, let’s say that the Local State of your Smart Contract makes use of just one single key/value pair (out of 16), for example a Unit named Balance. Since Balance is a Local variable, its value will be different from account to account, but is still going to be controlled by the same single Smart Contract logic. So if there are 100 accounts opted-in your Smart Contract, you will have 100 different Local states, each one with a specific value for the Balance key. The Smart Contract can read and write all those Local States.

Hope this clarifies better the Local State concept.

1 Like