pragma solidity ^0.4.18;

contract TwoD {

    address creater;
    string a;
    string b;

    function compareStrings (string a, string b) view returns (bool)
        /* warning 1: this line is showing No visibility specified warning but when i
           am using public it is showing error that expected token LBrace got public 
           warning 2: this declaration shadows existing declaration?
       return keccak256(a) == keccak256(b);

1 Answer 1


Here's a fiddle, I cleaned up your code with proper indentation and fixed the warnings (explained below):


As for the warnings you were getting:

1. "No visibility specified"

Change your function definition to

function compareStrings (string a, string b) view public returns (bool) {

to explicitly declare the function as public.

2. "This declaration shadows an existing declaration."

This is happening because you're declaring string a and string b at the start of your contract, then using those same variable names as arguments in your function. If your only purpose is to use them within that function, then you don't need to declare them outside of the function.

3. One more warning I was getting on your contract: "Function state mutability can be restricted to pure"

Your function doesn't need to read from storage, since the function is getting all its variables from its arguments. So you can set it as pure instead of view. (view would be used for, say, contract getters, where you need to access storage. pure is for utility methods that don't need to access storage, only its own function parameters).

Not the answer you're looking for? Browse other questions tagged or ask your own question.