In this smartbook, we'll discuss about storage and memory word in solidity:
Storage
- Hold only state variables
- Gas cost required
- persistent means it's stored in our main blockchain storage with immutable functionality.
- It's like a Hard Drive of our computer.
- String by default stored in Storage.
Example:
contract Practice {
uint public a = 20;
string public name = "Anurag";
}
Memory
- Hold only " Local Variables ".
- No Gas cost is required.
- Not-persistent means not stored in our main blockchain storage.
- Like RAM in the computer.
Example:
contract Practice {
function getter( string memory name) public pure returns(string memory){
return name;
}
}