Skip to content

Instantly share code, notes, and snippets.

@nishantrpai
Created September 18, 2024 01:11
Show Gist options
  • Save nishantrpai/e9c8bf1aedfebf622ab70e73023354bc to your computer and use it in GitHub Desktop.
Save nishantrpai/e9c8bf1aedfebf622ab70e73023354bc to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Chain is ERC721, Ownable {
uint256 public nextTokenId;
uint256 [] public colors;
constructor() ERC721("ChainNFT", "CHN") {
nextTokenId = 1;
svg = "<svg xmlns="http://www.w3.org/2000/svg" width="800" height="800" viewBox="0 0 620 620" fill="#fff" style="background:#fff">
<path d="M 312 162.75 L 172 302.5 L 213.875 343.875 L 282.375 275.125 L 282.42 462.5 H 343.125 V 275.125 L 412 343.875 L 453 302.5 L 313.25 162.75 H 312 Z" fill="#333"/>
<rect x="283" y="462" width="60" height="60" fill="#111" />
<rect x="283" y="521" width="60" height="60" fill="#999" />
</svg>";
colors = [];
}
function mint(address to, uint256 color) external onlyOwner {
_safeMint(to, nextTokenId);
nextTokenId++;
// add hex color to colors array
colors.push(color);
}
// dynamic tokenId return svg
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return string(abi.encodePacked("data:image/svg+xml;base64,", base64(bytes(svg))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment