Solidity - Error: Identifier not found or not unique. Compilation error

Viewed 17007

I had tried to compile this code by Compiler version 0.5.12, but I had an exception:

browser/Untitled.sol:21:24: DeclarationError: Identifier not found or not unique.

function getRoleOf(adress ad) public returns(string txt){

^----^

My code:

pragma solidity >=0.4.22 <0.5.13;
contract Max{
    mapping(address => uint256) private balaces;
    mapping(address => role) private roles;
    enum role{
        Admin,
        Manager,
        User
    }
    
    constructor() public{
        balaces[msg.sender] = 1000;
        roles[msg.sender] = role.Admin;
    }
    
    function getRoleOf(adress ad) public returns(string txt){
        if(roles[ad] == role.User){
            txt = "User";
            return;
        }
        if(roles[ad] == role.Manager){
            txt = "Manager";
            return;
        }
        if(roles[ad] == role.Admin){
            txt = "Admin";
            return;
        }
        return "Нет такого пользователя";
    }
}

What is wrong in my code?

4 Answers

The above answer(by @abcoathup) works with 0.4.26, if you want to execute your code in solidity version 0.5.12 check following code(with minor optimisation)

pragma solidity >=0.4.22 <0.5.13;
contract Max{
    mapping(address => uint256) private balaces;
    mapping(address => role) private roles;
    enum role{
        Admin,
        Manager,
        User
    }

    constructor() public{
        balaces[msg.sender] = 1000;
        roles[msg.sender] = role.Admin;
    }

    function getRoleOf(address ad) public returns(string memory txt){
        txt = "Нет такого пользователя";
        if(roles[ad] == role.User){
            txt = "User";
        } else if(roles[ad] == role.Manager){
            txt = "Manager";
        } else if(roles[ad] == role.Admin){
            txt = "Admin";
        }
        return txt;
    }
}

There is a typo in :function getRoleOf(adress ad) adress should be address

The following compiles in Remix using Solidity Compiler 0.4.26

pragma solidity >=0.4.22 <0.5.13;
contract Max{
    mapping(address => uint256) private balaces;
    mapping(address => role) private roles;
    enum role{
        Admin,
        Manager,
        User
    }

    constructor() public{
        balaces[msg.sender] = 1000;
        roles[msg.sender] = role.Admin;
    }

    function getRoleOf(address ad) public returns(string txt){
        if(roles[ad] == role.User){
            txt = "User";
            return;
        }
        if(roles[ad] == role.Manager){
            txt = "Manager";
            return;
        }
        if(roles[ad] == role.Admin){
            txt = "Admin";
            return;
        }
        return "Нет такого пользователя";
    }
}

getRoleOf(adress ad) --> getRoleOf(address ad)

Its spelling mistake address.

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract BlackLivesMatterToken is ERC20 { constructor(unit256 initialSupply) public ERC20("BlackLivesMatterToken", "BLM") { _mint(msg.sender, initialSupply); } }

Related