Last active
August 12, 2022 01:46
-
-
Save ChanJuiHuang/0f665fb92efe24d990051165e7ef85d8 to your computer and use it in GitHub Desktop.
erc721-basic.sol
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
// SPDX-License-Identifier: MIT | |
pragma solidity >= 0.8.4; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract XDNFT is ERC721 { | |
using Counters for Counters.Counter; | |
uint256 totalSupply = 2; | |
Counters.Counter private remainingNFT; | |
address payable private owner; | |
constructor() ERC721("XDNFT", "XDNFT") { | |
owner = payable(msg.sender); | |
remainingNFT._value = totalSupply; | |
initMint(); | |
} | |
function transfereNFTs(uint256[] calldata tokenIds, address to) public { | |
for (uint256 index = 0; index < tokenIds.length; index++) { | |
transferFrom(msg.sender, to, tokenIds[index]); | |
} | |
} | |
function initMint() private { | |
for (uint256 index = 0; index < totalSupply; index++) { | |
mint(); | |
} | |
} | |
function mint() private { | |
remainingNFT.decrement(); | |
uint256 tokenId = totalSupply - remainingNFT.current(); | |
_mint(msg.sender, tokenId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment