1

I'm developing a contract to manage multiple NFTs. The contract is an instance of ERC721, which manages some common attributes for every NFT.

Which could be the most efficient way to do it?

Option 1: Different mappings for each attribute.

mapping (uint256 => address) private _attribute1;
mapping (uint256 => uint256) private _attribute2;
mapping (uint256 => uint256) private _attribute3;
mapping (uint256 => uint256) private _attribute4;
mapping (uint256 => uint256) private _attribute5;

Option 2: One Struct and one mapping to store the structs.

 struct ItemDetails {
        address _attribute1;
        uint256 _attribute2;
        uint256 _attribute3;
        uint256 _attribute4;
        uint256 _attribute5;      
    }

mapping (uint256 => ItemDetails) private _itemDetailsMap;

1 Answer 1

0

Well I would say that if these are your NFTs attributes that you are storing on chain. Both of them are inefficient. Your going to have the user spend a lot of gas on the storage for that data.

Most efficient way to store data is with IPFS. You can store all the data you want on IPFS and the only thing that get's stored in the contract is the CID of your IPFS content. So the cost remains somewhat the same.

If it's not for that I would suggest going for the mapping since you can set one attribute at a time. Otherwise you could also run test on remix and see what is the amount of gas that is required for your use case and compare from that.

I answered this assuming the efficiency your talking about is the cost of gas per transaction.

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.