Storage variables can be marked as public during declaration:
publicName: public(String[64])The compiler automatically creates getter functions for all public storage variables. These getter functions are NOT written in your code, but are generated by the compiler when it compiles it.
For the example above, the compiler will generate a function named publicName that does not take any arguments and returns an String[64], the value of the state variable publicName. So, even if you cannot see any function named publicName, it will be generated when your code is compiled.
We need a public storage variable that tracks the number of pokemons created in the contract.
-
Create a
publicstorage variable namedtotalPokemonCountof typeuint256. -
Replace the key
0in the mappingpokemonListin the function_createPokemonwith the storage variabletotalPokemonCount. Remember to use theselfenvironment variable to access the storage variable from the function. -
In the
_createPokemonfunction, incrementtotalPokemonCountby 1 using theselfenvironment variable. To make the code look clean use the+=arithmetic operator as shown below:# adds 1 to the parameter passed @external def addOne(number: uint256): # we used += to increment number by 1 number += 1