// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title SimpleERC721
* @dev A simple ERC721 NFT contract with basic functionality
*/
contract SimpleERC721 is ERC721, Ownable {
uint256 private _nextTokenId;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
constructor(
string memory name,
string memory symbol
) ERC721(name, symbol) Ownable(msg.sender) {
_nextTokenId = 1;
}
/**
* @dev Returns the total amount of tokens stored by the contract
*/
function totalSupply() public view returns (uint256) {
return _nextTokenId - 1;
}
/**
* @dev Returns the token URI for a given token ID
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireOwned(tokenId);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via string.concat).
if (bytes(_tokenURI).length > 0) {
return string.concat(base, _tokenURI);
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets the token URI for a given token ID
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`.
*/
function _baseURI() internal pure override returns (string memory) {
return "";
}
}