simple view function in solidity

Viewed 31

i just want to check whether the address is whitelisted or not that is set in the whiteLister function.

pragma solidity 0.8.7;

// SPDX-License-Identifier: GPL-3.0

contract minter{
    function whiteLister( address _user) public{
    }

    function checkWhhiteListed(address user) public view returns (bool){
    )
}
2 Answers

You can use Mapping to keep track of the address which is whitelisted or not..

 // SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;

contract minter{

  mapping(address => bool) whiteList;

  function whiteLister( address _user) public{
    // whiteList the given address
    whiteList[_user] = true;
  }

  function checkWhhiteListed(address user) public view returns (bool){
    // return whether given address is whitelisted or not
    return whiteList[user];
  }

}

Thank you, I found a solution;

// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.7;

contract minter {

  mapping(address => bool) public whiteList;

  function whiteLister( address _user) public {
    // whiteList the given address
        whiteList[_user] = true;   
}} 
Related