BasicERC721.sol 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity 0.8.20;
  3. import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
  4. import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
  5. import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
  6. import { ERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
  7. import { ERC721Pausable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
  8. import { ERC721Burnable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
  9. /**
  10. * This file was generated with Openzeppelin Wizard and later modified.
  11. * GO TO: https://wizard.openzeppelin.com/#erc721
  12. */
  13. contract BasicERC721 is
  14. ERC721,
  15. ERC721Enumerable,
  16. ERC721Pausable,
  17. Ownable,
  18. ERC721Burnable
  19. {
  20. using Strings for uint256;
  21. uint256 private _nextTokenId;
  22. string private _tokenBaseURI;
  23. string private _contractURI;
  24. constructor(
  25. string memory name,
  26. string memory symbol,
  27. string memory tokenBaseURI,
  28. string memory contractURI_,
  29. address initialOwner
  30. ) ERC721(name, symbol) Ownable(initialOwner) {
  31. _tokenBaseURI = tokenBaseURI;
  32. _contractURI = contractURI_;
  33. }
  34. function safeMint(address to) external onlyOwner {
  35. unchecked {
  36. _nextTokenId++;
  37. }
  38. _safeMint(to, _nextTokenId);
  39. }
  40. function pause() external onlyOwner {
  41. _pause();
  42. }
  43. function unpause() external onlyOwner {
  44. _unpause();
  45. }
  46. function setBaseURI(string memory baseURI) external onlyOwner {
  47. _tokenBaseURI = baseURI;
  48. }
  49. function setContractURI(string memory contractURI_) external onlyOwner {
  50. _contractURI = contractURI_;
  51. }
  52. function _baseURI() internal view override returns (string memory) {
  53. return _tokenBaseURI;
  54. }
  55. function contractURI() external view returns (string memory) {
  56. return _contractURI;
  57. }
  58. /**
  59. * @dev Returns base uri and adds .json suffix
  60. * This is useful for metadata published on ipfs where files have .json suffix
  61. */
  62. function tokenURI(
  63. uint256 tokenId
  64. ) public view override returns (string memory) {
  65. if (ownerOf(tokenId) == address(0))
  66. revert ERC721NonexistentToken(tokenId);
  67. return
  68. bytes(_baseURI()).length > 0
  69. ? string(
  70. abi.encodePacked(_baseURI(), tokenId.toString(), ".json")
  71. )
  72. : "";
  73. }
  74. function _update(
  75. address to,
  76. uint256 tokenId,
  77. address auth
  78. )
  79. internal
  80. override(ERC721, ERC721Enumerable, ERC721Pausable)
  81. returns (address)
  82. {
  83. return super._update(to, tokenId, auth);
  84. }
  85. function _increaseBalance(
  86. address account,
  87. uint128 value
  88. ) internal override(ERC721, ERC721Enumerable) {
  89. super._increaseBalance(account, value);
  90. }
  91. function supportsInterface(
  92. bytes4 interfaceId
  93. ) public view override(ERC721, ERC721Enumerable) returns (bool) {
  94. return super.supportsInterface(interfaceId);
  95. }
  96. }