Solidity
在映射中依賴於參數的查找後找不到成員或不可見成員
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; } }
我想設置一個名字,我想得到我的名字。為此,我做了一個 getUser 函式。但我不知道我的名字。
但我有這樣的錯誤:
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; ^--------^
我該怎麼辦 ?
試試這個:
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 } }
希望能幫助到你。