2

This is the code

// SPDX-License-Identifier: MIT


pragma solidity >=0.7.0 <0.9.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol";
import "https://github.com/1001-digital/erc721-extensions/contracts/RandomlyAssigned.sol";

contract VasikTest is ERC721Enumerable, Ownable, RandomlyAssigned {  
    using Address for address;

    string public uriPrefix = "";
    string public uriSuffix = ".json";
    string public hiddenMetadataUri;
    
    // Starting and stopping sale, presale and whitelist
    bool public saleActive = false;
    bool public whitelistActive = false;
    bool public presaleActive = false;
    bool public revealed = false;


    // Reserved for the team, customs, giveaways, collabs and so on.
    uint256 public reserved = 2;

    // Price of each token
    uint256 public initial_price = 0.001 ether;
    uint256 public price;

    // Maximum limit of tokens that can ever exist
    uint256 public constant MAX_SUPPLY = 10;
    uint256 public constant MAX_PRESALE_SUPPLY = 5;
    uint256 public constant MAX_MINT_PER_TX = 2;


    // Team addresses for withdrawals
    address public a1;
    address public a2;
    address public a3;

    // List of addresses that have a number of reserved tokens for whitelist
    mapping (address => uint256) public whitelistReserved;


    constructor () ERC721 ("Vasik One mint", "OneMintVasik") RandomlyAssigned(MAX_SUPPLY,1) {
        price = initial_price;
        setHiddenMetadataUri("ipfs://QmVntyJMSn8FxYVHtWig3qtfFed5aH1mr7EeXx1nespWpu/hidden.json");
    }


    function tokenURI(uint256 _tokenId)
    public
    view
    virtual
    override
    returns (string memory)
  {
    require(
      _exists(_tokenId),
      "ERC721Metadata: URI query for nonexistent token"
    );

    if (revealed == false) {
      return hiddenMetadataUri;
    }

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, Strings.toString(_tokenId), uriSuffix))
        : "";
  }

    // See which address owns which tokens
    function tokensOfOwner(address addr) public view returns(uint256[] memory) {
        uint256 tokenCount = balanceOf(addr);
        uint256[] memory tokensId = new uint256[](tokenCount);
        for(uint256 i; i < tokenCount; i++){
            tokensId[i] = tokenOfOwnerByIndex(addr, i);
        }
        return tokensId;
    }

    // Exclusive whitelist minting
    function mintWhitelist(uint256 _amount) public payable {
        uint256 supply = totalSupply();
        uint256 reservedAmt = whitelistReserved[msg.sender];
        require( whitelistActive,                   "Whitelist isn't active" );
        require( reservedAmt > 0,                   "No tokens reserved for your address" );
        require( _amount <= reservedAmt,            "Can't mint more than reserved" );
        require( supply + _amount <= MAX_SUPPLY,    "Can't mint more than max supply" );
        require( msg.value == price * _amount,      "Wrong amount of ETH sent" );
        whitelistReserved[msg.sender] = reservedAmt - _amount;
        for(uint256 i = 1; i <= _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }

    // Presale minting
    function mintPresale(uint256 _amount) public payable {
        uint256 supply = totalSupply();
        require( presaleActive,                             "Sale isn't active" );
        require( _amount > 0 && _amount <= MAX_MINT_PER_TX, "Can only mint between 1 and 20 tokens at once" );
        require( supply + _amount <= MAX_PRESALE_SUPPLY,    "Can't mint more than max supply" );
        require( msg.value == price * _amount,              "Wrong amount of ETH sent" );
        for(uint256 i = 1; i <= _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }

    // Standard mint function
    function mintToken(uint256 _amount) public payable {
        uint256 supply = totalSupply();
        require( saleActive,                                "Sale isn't active" );
        require( _amount > 0 && _amount <= MAX_MINT_PER_TX, "Can only mint between 1 and 10 tokens at once" );
        require( supply + _amount <= MAX_SUPPLY,            "Can't mint more than max supply" );
        require( msg.value == price * _amount,              "Wrong amount of ETH sent" );
        for(uint256 i = 1; i <= _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }

    // Admin minting function to reserve tokens for the team, collabs, customs and giveaways
    function mintReserved(uint256 _amount) public onlyOwner {
        // Limited to a publicly set amount
        require( _amount <= reserved, "Can't reserve more than set amount" );
        reserved -= _amount;
        uint256 supply = totalSupply();
        for(uint256 i = 1; i <= _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }
    
    // Edit reserved whitelist spots
    function editWhitelistReserved(address[] memory _a, uint256[] memory _amount) public onlyOwner {
        for(uint256 i; i < _a.length; i++){
            whitelistReserved[_a[i]] = _amount[i];
        }
    }

    

    // Start and stop whitelist
    function setWhitelistActive(bool val) public onlyOwner {
        whitelistActive = val;
    }

    // Start and stop presale
    function setPresaleActive(bool val) public onlyOwner {
        presaleActive = val;
    }

    // Start and stop sale
    function setSaleActive(bool val) public onlyOwner {
        saleActive = val;
    }

      function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner {
    hiddenMetadataUri = _hiddenMetadataUri;
  }

  function setUriPrefix(string memory _uriPrefix) public onlyOwner {
    uriPrefix = _uriPrefix;
  }

  function setUriSuffix(string memory _uriSuffix) public onlyOwner {
    uriSuffix = _uriSuffix;
  }

    function setRevealed(bool _state) public onlyOwner {
    revealed = _state;
    }

    // Set a different price in case ETH changes drastically
    function setPrice(uint256 newPrice) public onlyOwner {
        price = newPrice;
    }

    // Set team addresses
    function setAddresses(address[] memory _a) public onlyOwner {
        a1 = _a[0];
        a2 = _a[1];
        a3 = _a[2];
    }

    // Withdraw funds from contract for the team
    function withdrawTeam(uint256 amount) public payable onlyOwner {
        uint256 percent = amount / 100;
        require(payable(a1).send(percent * 40));
        require(payable(a2).send(percent * 40));
        require(payable(a3).send(percent * 20));
    }

    function _baseURI() internal view virtual override returns (string memory) {
    return uriPrefix;
  }
}

The problem exist since i try to add the library RandomlyAssigned.sol, so i add it in the contract line contract VasikTest is ERC721Enumerable, Ownable, RandomlyAssigned {

And the problem that gives me is

  --> contracts/VasikTest.sol:11:1:
   |
11 | contract VasikTest is ERC721Enumerable, Ownable, RandomlyAssigned {  
   | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "WithLimitedSupply": 
  --> https://github.com/1001-digital/erc721-extensions/contracts/WithLimitedSupply.sol:28:5:
   |
28 |     function totalSupply() public view returns (uint256) {
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC721Enumerable": 
  --> https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol:45:5:
   |
45 |     function totalSupply() public view virtual override returns (uint256) {
   |     ^ (Relevant source part starts here and spans across multiple lines).

Can someone help me?

1
  • You have two functions with the same name totalSupply(). Therefore you need to either change the name of one of them, or override the conflict.
    – Sky
    Commented Jan 20, 2022 at 15:55

1 Answer 1

2

To override the conflict you should create yet a third function with the same name right in your contract which overrides the other two.

function totalSupply() public view virtual override(WithLimitedSupply, ERC721Enumerable) returns (uint256) {
    return _totalSupply;
}
2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Dec 22, 2022 at 14:26
  • Really?! A downvote for the only response and it's correct?!! Commented Jan 10, 2023 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.