I’m building an NFT marketplace with Solidity and using OpenZeppelin’s ERC-721 as the base contract. My tokens have 5 properties: id, hash, description, collection, and creator address. The hash points to IPFS where the actual image lives.
I’m confused about where to store this metadata. Right now I have an Asset struct with all these fields, and I store everything in my custom contract. When minting, I just pass the asset id and owner address to the ERC-721 functions.
This means all the real data lives outside the standard NFT contract. So what exactly is the NFT token itself? Are my properties part of my struct rather than the actual token?
Is this the right approach? Does ERC-721 only handle ownership and transfer logic? Or should I be storing metadata differently?
Here’s my current implementation:
pragma solidity ^0.5.0;
import "./ERC721Full.sol";
contract DigitalAssets is ERC721Full {
string public contractName;
Asset[] public assets;
uint public assetCounter = 0;
mapping(uint => bool) public _assetExists;
mapping(uint => Asset) public assetRegistry;
struct Asset {
uint tokenId;
string ipfsHash;
string title;
string category;
address payable creator;
}
event AssetMinted(
uint tokenId,
string ipfsHash,
string title,
string category,
address payable creator
);
constructor() public payable ERC721Full("DigitalAssets", "DIGI") {
contractName = "DigitalAssets";
}
function createAsset(string memory _hash, string memory _title, string memory _category) public {
require(bytes(_hash).length > 0);
require(bytes(_title).length > 0);
require(bytes(_category).length > 0);
require(msg.sender != address(0));
assetCounter++;
assetRegistry[assetCounter] = Asset(assetCounter, _hash, _title, _category, msg.sender);
require(!_assetExists[assetCounter]);
uint _tokenId = assets.push(assetRegistry[assetCounter]);
_mint(msg.sender, _tokenId);
_assetExists[assetCounter] = true;
emit AssetMinted(assetCounter, _hash, _title, _category, msg.sender);
}
}
Any feedback on improving this code would be great too. I’m pretty new to Ethereum development so thanks for any help!