How to let people add a nft(tokeID) of the collectionAddress of their choise to my contract to be able to store it on a mapping?

Viewed 49
//How to let people add a nft(tokeID) of the collectionAddress of their choise to my contract to be able to store it on a mapping? 

Any ideas, will be very helpfull.

i need to store the tokenID of diferent collection addressess like so : mapping (address => //tokenID of specific collectionAddress//)

i dont know how to let the contract know which tokeID belongs to any collection Address.

Sorry if i dont express very well my question, thanks for any ideas.

1 Answers

You can create a nested mapping.

mapping (address => mapping (address => uint256)) public userCollectionToken;

function store(address _user, address _collection, uint256 _tokenId) external {
    userCollectionToken[_user][_collection] = _tokenId;
}

Or you can store the combination of the collection address and the token ID in a struct, and then pass the struct to a regular mapping.

struct NFT {
    address collection;
    uint256 tokenID;
}

mapping (address => NFT) public userNFT;

function store(address _user, address _collection, uint256 _tokenId) external {
    userNFT[_user] = NFT(_collection, _tokenId);
}
Related