-
-
Save soenkeba/5df8ee90d600e8e3c9ceee0a6a3a23a0 to your computer and use it in GitHub Desktop.
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | |
contract sciencefaction is ERC1155 { | |
uint256 public constant DECENTRAFISH = 0x01559ae4021a4dcafee8abc36a5139b96d58cbba2fe6cd347c4ed6668011aac5; | |
uint256 public constant NFThistory = 0x01559ae4021a99b0d373d7bc8a80504bad782367abe12c21373c83adc6bf6a7e; | |
uint256 public constant IPFSforscher = 0x01559ae4021a9c84fa506cb76691054c2b92f655222cde2437d77ed21c083c4d; | |
constructor() public ERC1155("ipfs://f0{id}") { | |
_mint(msg.sender, DECENTRAFISH, 1, ""); | |
_mint(msg.sender, NFThistory, 1, ""); | |
_mint(msg.sender, IPFSforscher, 1, ""); | |
} | |
function mint( | |
address to, | |
uint256 id, | |
uint256 amount, | |
bytes memory data | |
) public virtual { | |
_mint(msg.sender, id, amount, data); | |
} | |
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) | |
); | |
} | |
} |
Hi sir, may i know how can i apply this idea into my dapp marketplace which has a form to create new NFT token? And the frontend is actually built using VueJS.
Does that mean i need to convert the IPFS CID to hex format upon upload using nodejs? I can't find any nodejs library which allowed us to convert the CID into hex.
+1 on above.. I've spent quite a while trying to work how to get the CID into hex in js but haven't managed.
I checked https://cid.ipfs.io/ and I see a 'DIGEST (HEX)' for my CID which I think could be the correct value but I'm not sure. Is there some library out there that can help?
PS. Very cool work around to the fixed erc1155 uri limitation!
@chrisalmeida here is example how you can get v1 CID
https://gist.github.com/tarassh/5d4f0bf32288771e9a5679da0bd82ac6
Hi, @soenkeba. What would it take to convert the result from below into a v0 CID within the same contract?