So I have been looking at solidity recently and got a hold of the voting app. Pretty simple to get a hold of. But here is what I am confused about (coming from the background of developing for the web/mobile):
In the context of a simple solidity based voting app that is holding the votes for a proposal
One can increase the vote when the method call is made. But there seems to be no explicit call to the 'blockchain' (and in that I am treating it like a database) to persist it. So does the EVM automatically write to the blockchain every-time I change a variable's value to the blockchain or does it do that once the function call ends and variable values have been finalized.
How does it decide which variables are to be written to the blockchain and which aren't. I might be using a simple counter variable (i=0) to keep track of a loop, say break out of the loop if it gets executed more than a 100 times. The counter is something I don't intend to persist to the blockchain.
- In some places it has also been suggested that a state is maintained inside a smart contract, if so how can the state be same for multiple users using the same application?