Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 861 Bytes

Storage, memory and stack.md

File metadata and controls

31 lines (23 loc) · 861 Bytes
  • Storage locations
    • Account storage
  • Replacing memory with calldata for saving gas

References

https://docs.soliditylang.org/en/latest/introduction-to-smart-contracts.html#storage-memory-and-the-stack

https://docs.soliditylang.org/en/latest/types.html#bytes-and-string-as-arrays

Code reference

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract HelloWorld {
    string private text;

    constructor() {
        text = "Hello World";
    }

    function helloWorld() public view returns (string memory)  {
        return text;
    }

    function setText(string calldata newText) public {
        text = newText;
    }
}