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

13,274

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;
    }
}
Share:
13,274

Related videos on Youtube

RUSLoker
Author by

RUSLoker

Updated on June 04, 2022

Comments

  • RUSLoker
    RUSLoker over 1 year

    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?

  • LAMG
    LAMG over 2 years
    you should add your code inside a code snippet and add a description