BasicERC1155.sol 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
  6. import { ERC1155Pausable } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
  7. import { ERC1155Burnable } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
  8. import { ERC1155Supply } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
  9. /**
  10. * This file was generated with Openzeppelin Wizard and later modified.
  11. * GO TO: https://wizard.openzeppelin.com/#erc1155
  12. */
  13. contract BasicERC1155 is
  14. ERC1155,
  15. Ownable,
  16. ERC1155Pausable,
  17. ERC1155Burnable,
  18. ERC1155Supply
  19. {
  20. using Strings for uint256;
  21. string public name;
  22. string public symbol;
  23. string private _contractURI;
  24. constructor(
  25. string memory _name,
  26. string memory _symbol,
  27. string memory baseURI,
  28. string memory contractURI_,
  29. address initialOwner
  30. ) ERC1155(baseURI) Ownable(initialOwner) {
  31. name = _name;
  32. symbol = _symbol;
  33. _contractURI = contractURI_;
  34. }
  35. function setContractURI(string memory contractURI_) external onlyOwner {
  36. _contractURI = contractURI_;
  37. }
  38. function setURI(string memory newuri) external onlyOwner {
  39. _setURI(newuri);
  40. }
  41. function pause() external onlyOwner {
  42. _pause();
  43. }
  44. function unpause() external onlyOwner {
  45. _unpause();
  46. }
  47. function mint(
  48. address account,
  49. uint256 id,
  50. uint256 amount
  51. ) external onlyOwner {
  52. _mint(account, id, amount, "");
  53. }
  54. function mintBatch(
  55. address to,
  56. uint256[] memory ids,
  57. uint256[] memory amounts
  58. ) external onlyOwner {
  59. _mintBatch(to, ids, amounts, "");
  60. }
  61. function contractURI() external view returns (string memory) {
  62. return _contractURI;
  63. }
  64. /**
  65. * @dev Returns base uri and adds .json suffix
  66. * This is useful for metadata published on ipfs where files have .json suffix
  67. */
  68. function uri(uint256 id) public view override returns (string memory) {
  69. return
  70. bytes(super.uri(id)).length > 0
  71. ? string(
  72. abi.encodePacked(super.uri(id), id.toString(), ".json")
  73. )
  74. : "";
  75. }
  76. function _update(
  77. address from,
  78. address to,
  79. uint256[] memory ids,
  80. uint256[] memory values
  81. ) internal override(ERC1155, ERC1155Pausable, ERC1155Supply) {
  82. super._update(from, to, ids, values);
  83. }
  84. }