This code does not compile:
pragma solidity >=0.8.0;
contract MyContract {
uint256 public foo = 314;
function myFunction() external view returns (uint256 result) {
assembly {
result := foo
}
}
}
This error is thrown:
TypeError: only local variables are supported. To access storage variables, use the ".slot" and ".offset" suffixes.
I modified my code like this:
result := foo.slot
But the result I got was "1" instead of "314". How can I get access to this storage variable in inline assembly?