Reputation: 23
when i type this code myUser memory user; give redline like "Identifier not found or not unique."
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
contract User {
struct MyUser {
address publicKey;
string userName;
}
MyUser[] public users;
function createUser(
string memory _userName
) public {
myUser memory user;
user.publicKey = msg.sender;
user.userName = _userName;
users.push(user);
}
}
Upvotes: 0
Views: 93
Reputation: 1440
You want to create a reference of MyUser struct but calling it as myUser..
Changing MyUser instead of myUser will fix the issue..
function createUser( string memory _userName) public {
MyUser memory user;
user.publicKey = msg.sender;
user.userName = _userName;
users.push(user);
}
Upvotes: 1