Storing State in a Smart Contract
Smart contracts give us the opportunity to store data in a stateful way, and where we can add and delete data within the smart contract, and then view a current state. So let’s do a simple contact of adding cities to a string array. Overall it will cost us some gas to add and delete strings, but not to view the state. The contract we will use is:
This has an add() method to add a new string to myArray, and a show() which will show the contents of myArray. The view element added to show() makes sure it is just a read function (and that we do not write to the function). We can then compile it in remix:
Now we can deploy:
This creates a new contact [here]: