0

I am new to solidity. I have a struct and an array of structs, like this:

struct Adopter{
    uint age;
    uint gender; // 0 woman, 1 man
    // maybe add an id field
}

Adopter[] adopters;

So, a person can adopt an animal only once. How do I keep adopters in such a way that I can check if the person already has adopted an animal? I can't search for a struct inside an array of structs and I can't create a mapping (struct => bool). There must be a simple way to achieve this.

  • You can just have bool adoptedPet in the struct. – Chan-Ho Suh Sep 21 at 1:25
0

You can make a mapping of addresses to structs and include a boolean in the struct.

Be sure to check this pattern: https://medium.com/robhitchens/solidity-crud-part-1-824ffa69509a

Hope it helps.

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.