Skip to content

Instantly share code, notes, and snippets.

@prtk418
Created August 18, 2021 17:00
Show Gist options
  • Save prtk418/195b27a40656c46924421efad787e297 to your computer and use it in GitHub Desktop.
Save prtk418/195b27a40656c46924421efad787e297 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.0+commit.9e61f92b.js&optimize=false&runs=200&gist=
pragma solidity >=0.6.0 <0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC721/ERC721.sol";
contract MyNft is ERC721 {
string NAME = "Abstract Collectibles";
string SYMBOL = "ABS";
uint256 private _tokenId;
address private _owner;
constructor() public ERC721(NAME, SYMBOL) {
_owner = msg.sender;
}
function mintCollectible(address receiver, string memory tokenURI) external returns (uint256) {
// only owner should be able to mint new NFTs
assert(msg.sender == _owner);
// unique id for nft in your collection
_tokenId += 1;
// finally mint out NFT to receiver
_mint(receiver, _tokenId);
// set tokenURI for plugging in our metadata to NFT
_setTokenURI(_tokenId, tokenURI);
return _tokenId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment