$npx -y skills add wshobson/agents --skill nft-standardsImplement NFT standards (ERC-721, ERC-1155) with proper metadata handling, minting strategies, and marketplace integration. Use when creating NFT contracts, building NFT marketplaces, or implementing digital asset systems.
| 1 | # NFT Standards |
| 2 | |
| 3 | Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Creating NFT collections (art, gaming, collectibles) |
| 8 | - Implementing marketplace functionality |
| 9 | - Building on-chain or off-chain metadata |
| 10 | - Creating soulbound tokens (non-transferable) |
| 11 | - Implementing royalties and revenue sharing |
| 12 | - Developing dynamic/evolving NFTs |
| 13 | |
| 14 | ## ERC-721 (Non-Fungible Token Standard) |
| 15 | |
| 16 | ```solidity |
| 17 | // SPDX-License-Identifier: MIT |
| 18 | pragma solidity ^0.8.0; |
| 19 | |
| 20 | import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; |
| 21 | import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; |
| 22 | import "@openzeppelin/contracts/access/Ownable.sol"; |
| 23 | import "@openzeppelin/contracts/utils/Counters.sol"; |
| 24 | |
| 25 | contract MyNFT is ERC721URIStorage, ERC721Enumerable, Ownable { |
| 26 | using Counters for Counters.Counter; |
| 27 | Counters.Counter private _tokenIds; |
| 28 | |
| 29 | uint256 public constant MAX_SUPPLY = 10000; |
| 30 | uint256 public constant MINT_PRICE = 0.08 ether; |
| 31 | uint256 public constant MAX_PER_MINT = 20; |
| 32 | |
| 33 | constructor() ERC721("MyNFT", "MNFT") {} |
| 34 | |
| 35 | function mint(uint256 quantity) external payable { |
| 36 | require(quantity > 0 && quantity <= MAX_PER_MINT, "Invalid quantity"); |
| 37 | require(_tokenIds.current() + quantity <= MAX_SUPPLY, "Exceeds max supply"); |
| 38 | require(msg.value >= MINT_PRICE * quantity, "Insufficient payment"); |
| 39 | |
| 40 | for (uint256 i = 0; i < quantity; i++) { |
| 41 | _tokenIds.increment(); |
| 42 | uint256 newTokenId = _tokenIds.current(); |
| 43 | _safeMint(msg.sender, newTokenId); |
| 44 | _setTokenURI(newTokenId, generateTokenURI(newTokenId)); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | function generateTokenURI(uint256 tokenId) internal pure returns (string memory) { |
| 49 | // Return IPFS URI or on-chain metadata |
| 50 | return string(abi.encodePacked("ipfs://QmHash/", Strings.toString(tokenId), ".json")); |
| 51 | } |
| 52 | |
| 53 | // Required overrides |
| 54 | function _beforeTokenTransfer( |
| 55 | address from, |
| 56 | address to, |
| 57 | uint256 tokenId, |
| 58 | uint256 batchSize |
| 59 | ) internal override(ERC721, ERC721Enumerable) { |
| 60 | super._beforeTokenTransfer(from, to, tokenId, batchSize); |
| 61 | } |
| 62 | |
| 63 | function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { |
| 64 | super._burn(tokenId); |
| 65 | } |
| 66 | |
| 67 | function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { |
| 68 | return super.tokenURI(tokenId); |
| 69 | } |
| 70 | |
| 71 | function supportsInterface(bytes4 interfaceId) |
| 72 | public |
| 73 | view |
| 74 | override(ERC721, ERC721Enumerable) |
| 75 | returns (bool) |
| 76 | { |
| 77 | return super.supportsInterface(interfaceId); |
| 78 | } |
| 79 | |
| 80 | function withdraw() external onlyOwner { |
| 81 | payable(owner()).transfer(address(this).balance); |
| 82 | } |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | ## ERC-1155 (Multi-Token Standard) |
| 87 | |
| 88 | ```solidity |
| 89 | // SPDX-License-Identifier: MIT |
| 90 | pragma solidity ^0.8.0; |
| 91 | |
| 92 | import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; |
| 93 | import "@openzeppelin/contracts/access/Ownable.sol"; |
| 94 | |
| 95 | contract GameItems is ERC1155, Ownable { |
| 96 | uint256 public constant SWORD = 1; |
| 97 | uint256 public constant SHIELD = 2; |
| 98 | uint256 public constant POTION = 3; |
| 99 | |
| 100 | mapping(uint256 => uint256) public tokenSupply; |
| 101 | mapping(uint256 => uint256) public maxSupply; |
| 102 | |
| 103 | constructor() ERC1155("ipfs://QmBaseHash/{id}.json") { |
| 104 | maxSupply[SWORD] = 1000; |
| 105 | maxSupply[SHIELD] = 500; |
| 106 | maxSupply[POTION] = 10000; |
| 107 | } |
| 108 | |
| 109 | function mint( |
| 110 | address to, |
| 111 | uint256 id, |
| 112 | uint256 amount |
| 113 | ) external onlyOwner { |
| 114 | require(tokenSupply[id] + amount <= maxSupply[id], "Exceeds max supply"); |
| 115 | |
| 116 | _mint(to, id, amount, ""); |
| 117 | tokenSupply[id] += amount; |
| 118 | } |
| 119 | |
| 120 | function mintBatch( |
| 121 | address to, |
| 122 | uint256[] memory ids, |
| 123 | uint256[] memory amounts |
| 124 | ) external onlyOwner { |
| 125 | for (uint256 i = 0; i < ids.length; i++) { |
| 126 | require(tokenSupply[ids[i]] + amounts[i] <= maxSupply[ids[i]], "Exceeds max supply"); |
| 127 | tokenSupply[ids[i]] += amounts[i]; |
| 128 | } |
| 129 | |
| 130 | _mintBatch(to, ids, amounts, ""); |
| 131 | } |
| 132 | |
| 133 | function burn( |
| 134 | address from, |
| 135 | uint256 id, |
| 136 | uint256 amount |
| 137 | ) external { |
| 138 | require(from == msg.sender || isApprovedForAll(from, msg.sender), "Not authorized"); |
| 139 | _burn(from, id, amount); |
| 140 | tokenSupply[id] -= amount; |
| 141 | } |
| 142 | } |
| 143 | ``` |
| 144 | |
| 145 | ## Metadata Standards |
| 146 | |
| 147 | ### Off-Chain Metadata (IPFS) |
| 148 | |
| 149 | ```json |
| 150 | { |
| 151 | "name": "NFT #1", |
| 152 | "description": "Description of the NFT", |
| 153 | "image": "ipfs://QmImageHash", |
| 154 | "attributes": [ |
| 155 | { |
| 156 | "trait_type": "Background", |
| 157 | "value": "Blue" |
| 158 | }, |
| 159 | { |
| 160 | "trait_type": "Rarity", |
| 161 | "value": "Legendary" |
| 162 | }, |
| 163 | { |
| 164 | "trait_type |