├── LICENSE ├── README.md └── nft.sol /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 FusedVR 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartContractExamples 2 | 3 | Sample Contracts used on the FusedVR Youtube Channel 4 | 5 | Here are some videos to get you started: 6 | 7 | - ERC 1155 NFT Template for Youtube Thumbnails : https://youtu.be/gulHi289hzU 8 | - Getting Started with ERC 20 Smart Contracts : https://youtu.be/z5i44_KUXDY 9 | - Unity + NEthereum Smart Contract Integration : https://youtu.be/suInD1bUUcM 10 | - The FASTEST Way To Test Metamask Smart Contracts with Unity Streaming : https://youtu.be/yRuqdHdDqFg 11 | -------------------------------------------------------------------------------- /nft.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol"; 5 | 6 | contract YTTokens is ERC1155PresetMinterPauser { 7 | 8 | uint256 public gameIDCounter; 9 | 10 | mapping(string => uint256) public idmap; 11 | mapping(uint256 => string) public lookupmap; 12 | 13 | 14 | constructor() ERC1155PresetMinterPauser("https://img.youtube.com/vi/") { //base URI 15 | 16 | } 17 | 18 | function addGameID( string memory gameID, uint256 initialSupply ) external { 19 | require(hasRole(MINTER_ROLE, _msgSender()), "YTTokens: must have minter role to mint"); 20 | 21 | require(idmap[gameID] == 0, "YTTokens: This gameID already exists"); 22 | 23 | gameIDCounter = gameIDCounter + 1; 24 | idmap[gameID] = gameIDCounter; 25 | lookupmap[gameIDCounter] = gameID; 26 | 27 | _mint(msg.sender, gameIDCounter, initialSupply, ""); 28 | } 29 | 30 | function uri(uint256 id) public view virtual override returns (string memory) { 31 | return string( abi.encodePacked( super.uri(id), lookupmap[id], "/hqdefault.jpg" )); 32 | } 33 | 34 | function getAllTokens(address account) public view returns (uint256[] memory){ 35 | uint256 numTokens = 0; 36 | for (uint i = 0; i <= gameIDCounter; i++) { 37 | if ( balanceOf(account, i) > 0) { 38 | numTokens++; 39 | } 40 | } 41 | 42 | uint256[] memory ret = new uint256[](numTokens); 43 | uint256 counter = 0; 44 | for (uint i = 0; i <= gameIDCounter; i++) { 45 | if ( balanceOf(account, i) > 0) { 46 | ret[counter] = i; 47 | counter++; 48 | } 49 | } 50 | 51 | return ret; 52 | } 53 | } --------------------------------------------------------------------------------