I’m building an NFT marketplace with Solidity and using OpenZeppelin’s ERC-721 contract as a base. Right now my tokens have 5 properties (id, hash, description, collection, and creator) and I store the IPFS hash for images.
I’m confused about where to put all this data. I created an Asset struct with these properties, add it to an array, then mint using the asset ID and owner address. But this means I’m keeping all the real data outside the ERC-721 contract.
This makes me wonder what the NFT actually is, since the properties belong to my struct and the NFT just references it. Is this the right approach? Does ERC-721 just handle the basic token functions while metadata lives elsewhere?
Here’s my current setup:
pragma solidity ^0.5.0;
import "./ERC721Full.sol";
contract ArtMarket is ERC721Full {
string public contractName;
Asset[] public tokens;
uint public assetCount = 0;
mapping(uint => bool) public _tokenExists;
mapping(uint => Asset) public assets;
struct Asset {
uint id;
string ipfsHash;
string title;
string category;
address payable creator;
}
event AssetMinted(
uint id,
string ipfsHash,
string title,
string category,
address payable creator
);
constructor() public payable ERC721Full("ArtMarket", "ARTMKT") {
contractName = "ArtMarket";
}
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));
assetCount++;
assets[assetCount] = Asset(assetCount, _hash, _title, _category, msg.sender);
require(!_tokenExists[assetCount]);
uint _tokenId = tokens.push(assets[assetCount]);
_mint(msg.sender, _tokenId);
_tokenExists[assetCount] = true;
emit AssetMinted(assetCount, _hash, _title, _category, msg.sender);
}
}
Any feedback on improving this code would be great. I’m new to Ethereum development so sorry if this seems basic.