Hyperinflation Crypto Vulnerability Discussion

I have already put “public” before “returns”, it said “from solidity:
Warning: Function state mutability can be restricted to view
–> ETH SC Security/Overflow.sol:13:5:
|
13 | function getBalance() public returns (uint) {
| ^ (Relevant source part starts here and spans across multiple lines).”

Then when I change “public” to “view” as below

function getBalance() public returns (uint) {
        return balance[msg.sender];
    }

it said
“from solidity:
SyntaxError: No visibility specified. Did you intend to add “public”?
–> ETH SC Security/Overflow.sol:13:5:
|
13 | function getBalance() view returns (uint) {
| ^ (Relevant source part starts here and spans across multiple lines).”

What should I do?

Never mind. I just got it right

function getBalance() view public returns (uint) {
        return balance[msg.sender];
    }
1 Like

Indeed, I also forgot to mention you about the view option that is mandatory if you want the function to return some kind of result.

So public and view are most of the times always together whenever a function should return something.

Carlos Z

1 Like