-
Notifications
You must be signed in to change notification settings - Fork 3
/
NFTMinterSolution
43 lines (30 loc) · 1.21 KB
/
NFTMinterSolution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: GPL-3.0
//contract address = 0x9a27677ed55CfA9Fb84549032baf035b55df6A74
pragma solidity ^0.8.0;
//import ERC721URIStorage.sol from OpenZeppelin
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
//create a contract NFTMINTERRINKEBY and inherit from ERC721URISTORAGE
contract NFTMinter is ERC721URIStorage{
//initialize variable for tracking _tokenID
uint256 _tokenID;
// add constructor
constructor() ERC721("NFTMinter", "NFTM") {
_tokenID = 0;
}
//create an event when NFT is minted args(tokenID, indexed NFTOwner, imageURL)
event NFTMinted(uint256 _tokenId, address indexed NFTOwner, string imageURL);
function getTokenID() public view returns(uint256){
return _tokenID;
}
function mintNFT(string memory _tokenURI) public {
_mintNFT(msg.sender, _tokenID, _tokenURI);
emit NFTMinted(_tokenID, msg.sender, _tokenURI);
}
//memory = RAM (lesser gas) | storage = storing on the blockchain (more gas)
//function _mintNFT() private
function _mintNFT(address _to, uint256 _tokenId, string memory _tokenURI) private{
_mint(_to, _tokenId);
_setTokenURI(_tokenId, _tokenURI);
_tokenID += 1;
}
}