Created
September 6, 2021 05:55
-
-
Save M4cs/e7ca34b18d7c5d8351b607fba94e9395 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | |
import './LittleShartsAdmins.sol'; | |
contract LittleShartCollectible is ERC721, ERC721URIStorage, ERC721Enumerable, LittleShartsAdmins { | |
using SafeMath for uint256; | |
string public baseURI; | |
uint256 public costToName; | |
uint256 public price = 1 ether; | |
uint256 public maxTokens; | |
uint256 public maxTokensPerMint = 10; | |
uint256 public _tokenIds=0; | |
mapping (uint256 => string) _names; | |
mapping (uint256 => uint256) _nameChangeCount; | |
mapping (string => uint256) _uniqueNames; | |
constructor( | |
string memory _baseURI, | |
uint256 _costToName, | |
uint256 _maxTokens, | |
address _masterAdmin | |
) ERC721("Little Sharts", "LSHRT") { | |
baseURI = _baseURI; | |
costToName = _costToName; | |
maxTokens = _maxTokens; | |
masterAdmin = _masterAdmin; | |
} | |
function mintShart( | |
string[] memory names, | |
uint256 amount | |
) payable public { | |
require(msg.value >= (amount * price), "Not enough funds sent to cover transaction!"); | |
uint256[] memory newItems = new uint256[](amount); | |
require(names.length == amount, "Provided too many or too little names in relation to the amount!"); | |
require((_tokenIds+amount) <= maxTokens, "Not enough remaining tokens to mint that many!"); | |
require(amount <= maxTokensPerMint, "Requested to mint too many tokens!"); | |
for (uint i=0;i<amount;i++) { | |
uint256 newItemId = _tokenIds+1; | |
require(_uniqueNames[names[i]] == 0, "One of your names is already taken!"); | |
_names[newItemId] = names[i]; | |
_uniqueNames[names[i]] = newItemId; | |
_safeMint(msg.sender, newItemId); | |
_setTokenURI(newItemId, uint2str(newItemId)); | |
newItems[i] = newItemId; | |
_tokenIds++; | |
} | |
payable(address(masterAdmin)).transfer(msg.value); | |
} | |
function updateURI(string memory newURI) public onlyAdmin { | |
baseURI = newURI; | |
} | |
function updateMaxTokens(uint256 _maxTokens) public onlyAdmin { | |
require(_maxTokens > maxTokens, "New count must be higher than old count!"); | |
maxTokens = _maxTokens; | |
} | |
function tokensOwned() public view returns (uint256[] memory) { | |
uint balance = balanceOf(msg.sender); | |
uint256[] memory tOwned = new uint256[](balance); | |
for (uint i=0;i<balance;i++) { | |
tOwned[i] = tokenOfOwnerByIndex(msg.sender, i); | |
} | |
return tOwned; | |
} | |
function tokensOwned(address _owner) public view returns (uint256[] memory) { | |
uint balance = balanceOf(_owner); | |
uint256[] memory tOwned = new uint256[](balance); | |
for (uint i=0;i<balance;i++) { | |
tOwned[i] = tokenOfOwnerByIndex(_owner, i); | |
} | |
return tOwned; | |
} | |
function uint2str(uint _i) internal pure returns (string memory _uintAsString) { | |
if (_i == 0) { | |
return "0"; | |
} | |
uint j = _i; | |
uint len; | |
while (j != 0) { | |
len++; | |
j /= 10; | |
} | |
bytes memory bstr = new bytes(len); | |
uint k = len; | |
while (_i != 0) { | |
k = k-1; | |
uint8 temp = (48 + uint8(_i - _i / 10 * 10)); | |
bytes1 b1 = bytes1(temp); | |
bstr[k] = b1; | |
_i /= 10; | |
} | |
return string(bstr); | |
} | |
function tokenURI(uint256 _id) public view override(ERC721, ERC721URIStorage) returns (string memory) { | |
return string(abi.encodePacked(baseURI, uint2str(_id), ".json")); | |
} | |
function _burn(uint256 tokenId) internal virtual override(ERC721, ERC721URIStorage) { | |
super._burn(tokenId); | |
} | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) { | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) { | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment