A function can read the state (storage variables), but cannot modify it.
Usage:
A function cannot read or write to the blockchain state. It is entirely self-contained, like a mathematical function.
Usage
msg.sender, block.timestamp, storage variables, etc.function add(uint a, uint b) public pure returns (uint) {
return a + b; // uses only inputs, not state
}
A function overrides a parent contract’s virtual function.
virtual.contract A {
function greet() public virtual returns (string memory) {
return "Hello from A";
}
}
contract B is A {
function greet() public override returns (string memory) {
return "Hello from B";
}
}