0

Can someone help me with a nested struct , i am unable to map the nested struct my problem statement is i need to get a accept a user details name gender etc and his home address as well in a struct , i tried this didnt get anywhere:-

struct Pdetails {
    
    string fName;
    string lName
    int256 age;
        enum gender;
    }
struct Addr{
    
    string line 1;
    string line 2;
    string city;
    string state;
    int256 pincode;
    }
0

You can combine both of the structs into a new struct to store the information of the user. for example:

pragma solidity 0.8.2;

contract PersonalInfo{
    
    enum gender {MALE, FEMALE}
    
    struct Pdetails {
    
        string fName;
        string lName;
        int256 age;
        gender Gender;
    }
    
    struct Addr{
    
        string line;
        string city;
        string state;
        int256 pincode;
    }
  
    struct UserInfo{
        
        Addr addr;
        Pdetails pdetails;
    }
}
1
  • can u help me map these as well? i am trying to get user info of above parameters, i posted my code in answer – user 404 not found Apr 18 at 0:57
0

function createUser(address _userAddress, uint256 _userId, string _fName, string _lName, int256 _age, enum _gender, string _line1, string _line2, string _city, string _state, int256 _pincode  ) public {
    User storage user = users[_userAddress];
    require(!user.set);
    
    //Store the user
    users[_userAddress] = User(
        {
        id: _userId,
        first_name: _fName,
        last_name: _lName,
        age: _age,
        gender : _gender,
        Addr line1: _line1,
        Addr line2: _line2,
        city: _city,
        state: _state,
        pincode: _pincode
        
        set: true
    }
    );
}
i tried to map these but i dont think this is the right way to do it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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