Created
October 26, 2021 03:20
-
-
Save soenkeba/a5244cc13441e84340bcc945c60e27c5 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 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
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | |
/** | |
* @dev String operations. | |
*/ | |
library Strings { | |
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` decimal representation. | |
*/ | |
function toString(uint256 value) internal pure returns (string memory) { | |
// Inspired by OraclizeAPI's implementation - MIT licence | |
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol | |
if (value == 0) { | |
return "0"; | |
} | |
uint256 temp = value; | |
uint256 digits; | |
while (temp != 0) { | |
digits++; | |
temp /= 10; | |
} | |
bytes memory buffer = new bytes(digits); | |
while (value != 0) { | |
digits -= 1; | |
buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); | |
value /= 10; | |
} | |
return string(buffer); | |
} | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. | |
*/ | |
function toHexString(uint256 value) internal pure returns (string memory) { | |
if (value == 0) { | |
return "0x00"; | |
} | |
uint256 temp = value; | |
uint256 length = 0; | |
while (temp != 0) { | |
length++; | |
temp >>= 8; | |
} | |
return toHexString(value, length); | |
} | |
/** | |
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. | |
*/ | |
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { | |
bytes memory buffer = new bytes(2 * length + 2); | |
buffer[0] = "0"; | |
buffer[1] = "x"; | |
for (uint256 i = 2 * length + 1; i > 1; --i) { | |
buffer[i] = _HEX_SYMBOLS[value & 0xf]; | |
value >>= 4; | |
} | |
require(value == 0, "Strings: hex length insufficient"); | |
return string(buffer); | |
} | |
} | |
contract sciencefaction is ERC1155 { | |
uint256 public constant DECENTRAFISH = 0x01559ae4021a4dcafee8abc36a5139b96d58cbba2fe6cd347c4ed6668011aac5; | |
uint256 public constant NFThistory = 0x01559ae4021a99b0d373d7bc8a80504bad782367abe12c21373c83adc6bf6a7e; | |
uint256 public constant IPFSforscher = 0x01559ae4021a9c84fa506cb76691054c2b92f655222cde2437d77ed21c083c4d; | |
function mint( | |
address to, | |
uint256 id, | |
uint256 amount, | |
bytes memory data | |
) virtual public { | |
_mint(to, id, amount, data); | |
} | |
constructor() public ERC1155("ipfs://f0{id}") { | |
_mint(msg.sender, DECENTRAFISH, 1, ""); | |
_mint(msg.sender, NFThistory, 1, ""); | |
_mint(msg.sender, IPFSforscher, 1, ""); | |
} | |
function uint2hexstr(uint256 i) public pure returns (string memory) { | |
if (i == 0) return "0"; | |
uint j = i; | |
uint length; | |
while (j != 0) { | |
length++; | |
j = j >> 4; | |
} | |
uint mask = 15; | |
bytes memory bstr = new bytes(length); | |
uint k = length; | |
while (i != 0) { | |
uint curr = (i & mask); | |
bstr[--k] = curr > 9 ? | |
bytes1(uint8(55 + curr)) : | |
bytes1(uint8(48 + curr)); // 55 = 65 - 10 | |
i = i >> 4; | |
} | |
return string(bstr); | |
} | |
function uri(uint256 _tokenID) override public view returns (string memory) { | |
string memory hexstringtokenID; | |
hexstringtokenID = uint2hexstr(_tokenID); | |
return string( | |
abi.encodePacked( | |
"ipfs://f0", | |
hexstringtokenID) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment