all files / contracts/examples/ VotingPrizeNFT.sol

0% Statements 0/7
0% Branches 0/4
0% Functions 0/3
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
import {ERC721URIStorage} from '@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol';
import {ERC721} from '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import {Counters} from '@openzeppelin/contracts/utils/Counters.sol';
 
/// @title VotingPrizeNFT
contract VotingPrizeNFT is ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
 
    address public owner;
    address public voting;
    string public metadataURI;
 
    constructor(string memory _metadataURI) ERC721('VotingPrizeNFT', 'Prize') {
        owner = msg.sender;
        metadataURI = _metadataURI;
    }
 
    function setVotingAddress(address _voting) public {
        require(msg.sender == owner);
        voting = _voting;
    }
 
    function awardItem(address winner) public returns (uint256) {
        require(msg.sender == voting);
        uint256 newItemId = _tokenIds.current();
        _mint(winner, newItemId);
        _setTokenURI(newItemId, metadataURI);
 
        _tokenIds.increment();
        return newItemId;
    }
}