-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFTs.sol
26 lines (21 loc) · 870 Bytes
/
NFTs.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract MyNFT is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping (uint256 => string) private _tokenURIs;
constructor() ERC721("MyNFT", "NFT") {}
function createNFT(address recipient, string memory tokenURI) public returns (uint256){
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(recipient, newTokenId);
_setTokenURI(newTokenId, tokenURI);
return newTokenId;
}
function _setTokenURI(uint256 tokenId, string memory tokenURI) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI does not exist");
_tokenURIs[tokenId] = tokenURI;
}
}