BasicERC1155.sol 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity 0.8.28;
  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 ERC1155, Ownable, ERC1155Pausable, ERC1155Burnable, ERC1155Supply {
  14. using Strings for uint256;
  15. string public name;
  16. string public symbol;
  17. string private _contractURI;
  18. constructor(
  19. string memory _name,
  20. string memory _symbol,
  21. string memory baseURI,
  22. string memory contractURI_,
  23. address initialOwner
  24. ) ERC1155(baseURI) Ownable(initialOwner) {
  25. name = _name;
  26. symbol = _symbol;
  27. _contractURI = contractURI_;
  28. }
  29. function setContractURI(string memory contractURI_) external onlyOwner {
  30. _contractURI = contractURI_;
  31. }
  32. function setURI(string memory newuri) external onlyOwner {
  33. _setURI(newuri);
  34. }
  35. function pause() external onlyOwner {
  36. _pause();
  37. }
  38. function unpause() external onlyOwner {
  39. _unpause();
  40. }
  41. function mint(address account, uint256 id, uint256 amount) external onlyOwner {
  42. _mint(account, id, amount, "");
  43. }
  44. function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) external onlyOwner {
  45. _mintBatch(to, ids, amounts, "");
  46. }
  47. function contractURI() external view returns (string memory) {
  48. return _contractURI;
  49. }
  50. /**
  51. * @dev Returns base uri and adds .json suffix
  52. * This is useful for metadata published on ipfs where files have .json suffix
  53. */
  54. function uri(uint256 id) public view override returns (string memory) {
  55. return bytes(super.uri(id)).length > 0 ? string(abi.encodePacked(super.uri(id), id.toString(), ".json")) : "";
  56. }
  57. function _update(
  58. address from,
  59. address to,
  60. uint256[] memory ids,
  61. uint256[] memory values
  62. ) internal override(ERC1155, ERC1155Pausable, ERC1155Supply) {
  63. super._update(from, to, ids, values);
  64. }
  65. }