Advertisement
danny1995

NFTBaseERC1155.sol

Oct 29th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | Cryptocurrency | 0 0
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.3;
  3.  
  4. import "@openzeppelin/contracts/utils/Strings.sol";
  5. import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
  6. import "@openzeppelin/contracts/access/Ownable.sol";
  7. import "@openzeppelin/contracts/security/Pausable.sol";
  8. import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
  9. import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
  10.  
  11.  
  12. contract NFTBaseERC1155 is ERC1155, Ownable, Pausable, ERC1155Burnable, ERC1155Supply {
  13.  
  14. uint16[] supplies=[100,200,300]; //Total No of nft that can me minted
  15. uint16[] minted=[0,0,0]; //Total nft minted
  16. uint256[] rates=[1 ether,3 ether,5 ether]; //Price for minting nft
  17.  
  18. mapping(uint256 => address) private _owners;
  19.  
  20. constructor() ERC1155("https://nftstorage.link/ipfs/bafybeie3to4rlzcmksld2zyevtmectcgyu5oleslijbzb42acglxivgkny/{id}.json") {}
  21.  
  22. function setURI(string memory newuri) public onlyOwner {
  23. _setURI(newuri);
  24. }
  25.  
  26. function pause() public onlyOwner {
  27. _pause();
  28. }
  29.  
  30. function unpause() public onlyOwner {
  31. _unpause();
  32. }
  33.  
  34. modifier check_nft_type_balance_and_supply(uint16 id,uint16 amount) {
  35. require(id<=supplies.length,"Token doesn't exist");
  36. require(id>0,"Token doesn't exist");
  37. require((minted[returnIndex(id)]+amount)<=supplies[returnIndex(id)],"Not enough supply");
  38. require(msg.value>=amount*rates[returnIndex(id)],"Not enough balance");
  39. _;
  40. }
  41.  
  42. function returnIndex(uint16 index)public pure returns(uint16){
  43. return index-1;
  44. }
  45.  
  46. function mint(uint16 id, uint16 amount)
  47. public payable check_nft_type_balance_and_supply(id,amount)
  48. {
  49. _mint(msg.sender,id,amount,"");
  50. minted[returnIndex(id)]+=amount;
  51. }
  52.  
  53.  
  54. function MintBatch() public{
  55.  
  56. for(uint16 i=2; i<=43; i++){
  57. _mint(msg.sender,i,1,"");
  58. _owners[i]=msg.sender;
  59. }
  60. }
  61.  
  62. function withdraw() public onlyOwner {
  63. require(address(this).balance >0,"Balance is zero");
  64. payable(owner()).transfer(address(this).balance);
  65. }
  66.  
  67. function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
  68. internal
  69. whenNotPaused
  70. override(ERC1155, ERC1155Supply)
  71. {
  72. super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
  73. }
  74.  
  75.  
  76. function uri(uint256 _tokenid) override public pure returns (string memory) {
  77. return string(
  78. abi.encodePacked(
  79. "https://nftstorage.link/ipfs/bafybeie3to4rlzcmksld2zyevtmectcgyu5oleslijbzb42acglxivgkny/",
  80. Strings.toString(_tokenid),".json"
  81. )
  82. );
  83.  
  84. }
  85.  
  86. function ownerOf(uint256 tokenId) public view returns (address) {
  87. address owner = _owners[tokenId];
  88. require(owner != address(0), "ERC1155: owner query for nonexistent token");
  89. return owner;
  90. }
  91.  
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement