-
Notifications
You must be signed in to change notification settings - Fork 0
/
company-nft.sol
52 lines (42 loc) · 1.38 KB
/
company-nft.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract CryptoVitaeCompanyNFT is ERC721, Ownable {
uint256 public tokenCounter;
mapping(uint256 => string) private _tokenURIs;
mapping(address => uint256[]) private _ownedTokens;
constructor() ERC721("CryptoVitaeCompanyNFT", "CVC") Ownable(msg.sender) {
tokenCounter = 0;
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(
ownerOf(tokenId) != address(0),
"ERC721Metadata: URI query for nonexistent token"
);
return _tokenURIs[tokenId];
}
function createNFT(string memory _tokenURI)
public
returns (uint256)
{
require(bytes(_tokenURI).length > 0, "Token URI is required");
uint256 tokenId = tokenCounter;
_safeMint(msg.sender, tokenId);
_ownedTokens[msg.sender].push(tokenId);
_setTokenURI(tokenId, _tokenURI);
tokenCounter++;
return tokenId;
}
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
_tokenURIs[tokenId] = _tokenURI;
}
function tokensOfOwner() external view returns (uint256[] memory) {
return _ownedTokens[msg.sender];
}
}