0
contract GalaxyExplorer is ERC721Enumerable{
    struct Land {
        string name;
        address tenant;
        uint256 x;
        uint256 y;
    }
    struct Planet {
        string name;
        address owner;
        uint256 x;
        uint256 y;
        mapping(uint256 => Land) lands;
    }
    mapping(uint256 => Planet) public planets;
    
    constructor() ERC721("Galaxy Explorer", "GE") {
        planets[0].name = 'Genexy';
        planets[0].owner = msg.sender;
        planets[0].x = 0;
        planets[0].y = 0;
        planets[0].lands[0] = Land('Alpha', address(0), 0, 0);
    }
}

As above, have multiple planets in the galaxy, each planet have multiple lands. Each planet have own erc721 tokenId and map to struct with variables. The only way to retrieve planet now is by knowing their tokenId, which is planets[0] can get Genexy, but even though can get with tokenId, the lands of planet is not retrievable! I'm stuck on this while trying to learn solidity to build a mini game. Found that using a for loop with tokenId was able to retrieve those planets, but still without lands. Even with for loop, if planets grow to ten thousand or million, its hard to retrieve all datas. Maybe take hours to load all million of planets?

1

Your Answer

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

Browse other questions tagged or ask your own question.