Storage, Memory and Stack in Solidity Ethereum Smart Contracts
In Solidity or particularly ethereum smart contracts data are stored in 3 ways:-
- Storage
- Memory
- Stack
Storage
- It stores data in blockchain form
- It store data permanently and no one can change it
- It’s costly. It have high Gas Fee (cost to run smart contract on EVM)
- generally data of users, tokens and balance are stored here
- It have higher gas fee because it’s stored in blockchain.
Memory
- Its short term memory, it’s stored data during code/function execute
- Its like storing something on RAM. when program completed, RAM cleaned
- Its cheaper than Storage and Stack
- Its not stored in blockchain, its just simple storage stored for sometime.
- Its also not stored in any storage — database, its stored in the function itself.
Stack
- It store data in personal database of Ethereum, not in Ethereum blockchain
- Its cheaper than storage
- Its generally used to store temporary data which’re needed for immidiate processing
To understand there words properly, and get actual costs, make DApps, because best way to learn swimming is “Jump into the water”