0
pragma solidity >=0.4.0 <0.7.0;

contract New{

    mapping(address => string) public users;

    string name;

    address[] public userAddress ;
    //string[] public userNames;

    function updateUser(string memory name) public{
        users[msg.sender]= name;

    }
    function getUser(address[] calldata) external view returns(string memory){
        return users.name;
    }

}

I want to set a name and I want to get my name.For this reason I made a getUser func. but I can't get my name.

but I have got a error like this :

browser/asd.sol:17:16: TypeError: Member "name" not found or not visible after argument-dependent lookup in mapping(address => string storage ref). return users.name; ^--------^

what should I do ?

1 Answer 1

1

Try this:

pragma solidity >=0.4.0 <0.7.0;

contract New{

    mapping(address => string) public users; // contains a name for every address

    // string name;

    // address[] public userAddress ;
    // string[] public userNames;

    function updateUser(string memory name) public {
        users[msg.sender] = name; // set name for address

    }
    function getUser(address a) public view returns(string memory) {
        return users[a]; // return address name
    }
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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