1

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.

1
  • You can just have bool adoptedPet in the struct. Sep 21, 2019 at 1:25

1 Answer 1

1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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