Skip to content

Instantly share code, notes, and snippets.

@ryanckulp
Last active January 15, 2022 09:48
Show Gist options
  • Select an option

  • Save ryanckulp/aabf152b16dd535da91cad7e8397d75a to your computer and use it in GitHub Desktop.

Select an option

Save ryanckulp/aabf152b16dd535da91cad7e8397d75a to your computer and use it in GitHub Desktop.

Revisions

  1. ryanckulp renamed this gist Jan 15, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions KlaytnContract.sol → KlaytnContractTemplate.sol
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ import "@openzeppelin/contracts/utils/Counters.sol";
    import "@openzeppelin/contracts/utils/math/SafeMath.sol";


    contract KlaytnTemplate is ERC721, ERC721Enumerable, Ownable {
    contract KlaytnContractTemplate is ERC721, ERC721Enumerable, Ownable {
    using SafeMath for uint256; // for invocation of mul()

    // this template is provided by and explained by https://ooju.xyz
    @@ -29,7 +29,7 @@ contract KlaytnTemplate is ERC721, ERC721Enumerable, Ownable {

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("Klaytn Template", "KlaytnTemplate") {}
    constructor() ERC721("Klaytn Contract Template", "KlaytnContractTemplate") {}

    /**
    * OWNER ONLY
  2. ryanckulp created this gist Jan 15, 2022.
    79 changes: 79 additions & 0 deletions KlaytnContract.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.2;

    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
    import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    import "@openzeppelin/contracts/utils/Counters.sol";
    import "@openzeppelin/contracts/utils/math/SafeMath.sol";


    contract KlaytnTemplate is ERC721, ERC721Enumerable, Ownable {
    using SafeMath for uint256; // for invocation of mul()

    // this template is provided by and explained by https://ooju.xyz

    /**
    * @dev Constants
    */
    uint public constant ASSET_LIMIT = 5;

    /**
    * @dev Variables
    */
    string private _baseURIextended;
    bool internal uriSet;
    uint[ASSET_LIMIT] private indices;

    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("Klaytn Template", "KlaytnTemplate") {}

    /**
    * OWNER ONLY
    */

    function setBaseURI(string memory baseURI_) external onlyOwner() {
    uriSet = true;
    _baseURIextended = baseURI_;
    }

    function giveaway(address receiver, uint256 numAssets) external onlyOwner {
    require(uriSet == true, "Base URI not set, do that first and then giveaway");
    require(totalSupply().add(numAssets) <= ASSET_LIMIT, "There are not enough assets left");

    for (uint i = 0; i < numAssets; i++) {
    uint id;
    id = _tokenIdCounter.current();

    // start edition at #1 vs #0
    if (id == 0) {
    _tokenIdCounter.increment();
    id = _tokenIdCounter.current();
    }

    _safeMint(receiver, id);
    _tokenIdCounter.increment();
    }
    }

    /**
    * OVERRIDES
    */

    function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
    return super.supportsInterface(interfaceId);
    }

    // used by inherited 'function tokenURI'
    function _baseURI() internal view virtual override returns (string memory) {
    return _baseURIextended;
    }

    function _beforeTokenTransfer(address from, address to, uint256 tokenId)
    internal override(ERC721, ERC721Enumerable) {
    super._beforeTokenTransfer(from, to, tokenId);
    }
    }