Last active
March 6, 2022 22:44
-
-
Save dabit3/ffdfc03a9279761154eebfea251f0e29 to your computer and use it in GitHub Desktop.
Basic NFT Smart Contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/NFT.sol | |
// SPDX-License-Identifier: MIT OR Apache-2.0 | |
pragma solidity ^0.8.3; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "hardhat/console.sol"; | |
contract NFT is ERC721URIStorage { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
address contractAddress; | |
constructor(address marketplaceAddress) ERC721("Metaverse Tokens", "METT") { | |
contractAddress = marketplaceAddress; | |
} | |
function createToken(string memory tokenURI) public returns (uint) { | |
_tokenIds.increment(); | |
uint256 newItemId = _tokenIds.current(); | |
_mint(msg.sender, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
setApprovalForAll(contractAddress, true); | |
return newItemId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment