Skip to content

Commit a00f210

Browse files
committed
Update RaffleNFT.sol
1 parent 9530e4c commit a00f210

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

contracts/RaffleNFT.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ contract RaffleNFT is ERC721, ReentrancyGuard, Ownable {
1919
uint256 public endTime;
2020
/// @notice Base URI for NFT metadata
2121
string private baseTokenURI;
22-
uint256 private _tokenIdCounter;
22+
/// @notice Total number of tokens minted
23+
uint256 public totalSupply;
2324
/// @notice Mapping from token ID to owner address (for quick access)
2425
mapping(uint256 => address) public tokenOwners;
2526
/// @notice Last mint time (timestamp, unix time) for each address
@@ -86,16 +87,16 @@ contract RaffleNFT is ERC721, ReentrancyGuard, Ownable {
8687
address winner = owner();
8788
winnerAddress = address(0);
8889

89-
if (_tokenIdCounter > 0) {
90+
if (totalSupply > 0) {
9091
uint256 winnerTokenId = uint256(
9192
keccak256(abi.encodePacked(
9293
block.prevrandao,
9394
address(this),
9495
tx.gasprice,
9596
gasleft(),
96-
_tokenIdCounter
97+
totalSupply
9798
))
98-
) % _tokenIdCounter;
99+
) % totalSupply;
99100
winner = ownerOf(winnerTokenId);
100101
winnerAddress = winner;
101102
}
@@ -124,10 +125,10 @@ contract RaffleNFT is ERC721, ReentrancyGuard, Ownable {
124125
block.timestamp - lastMintTime[msg.sender] >= 1 days,
125126
"You can only mint once every 24 hours"
126127
);
127-
uint256 tokenId = _tokenIdCounter;
128+
uint256 tokenId = totalSupply;
128129
_mint(msg.sender, tokenId);
129130
tokenOwners[tokenId] = msg.sender;
130-
_tokenIdCounter++;
131+
totalSupply++;
131132
lastMintTime[msg.sender] = block.timestamp;
132133
}
133134

0 commit comments

Comments
 (0)