[Ethereum] Unused function parameter. Remove or comment out the variable name to silence this warning

addressesremixsoliditytruffletruffle-compile

I have a smart contact which have 2 owner address and 3 functions.

my set functions is set a users with msg.sender and my getUser functions is returns name,surname and age and I want to add a admin which can set users to . This setUsersbyAdmin function take an address parameter for set name,surname and ag.

My smart contract works well on remix but I try to truffle compile it failed.

here's the code :

pragma solidity >=0.4.0 <0.7.0;

contract NewHello{ 

    address owner;
    address newOwner;

    constructor()public{
        owner = msg.sender;
    }

    modifier onlyOwner (){
        if(msg.sender != owner){
            require(msg.sender == newOwner);
            _;
        }
        else{
            require(msg.sender == owner);
            _;
        }

    }

    struct user{
        string name;
        string surname;
        uint age;
    }
     event infoChanged(
        string name,
        string surname,
        uint age
    );

    mapping(address => user) public users; // contains a user for every address

    function setUser(string memory name,string memory surname,uint age) public payable{
        users[msg.sender] = user(name,surname,age);
        emit infoChanged(name,surname,age);
    }
    function setUserbyAdmin(address _address, string memory name,string memory surname,uint age) public payable onlyOwner{
        users[msg.sender] = user(name,surname,age);
        emit infoChanged(name,surname,age);
    }

    function getUser(address _address) public view returns(string memory name , string memory surname, uint age)  {

        return (users[_address].name,users[_address].surname,users[_address].age);        
    }
}

when I compile this with truffle I see an error on my window which says :

Warning: Unused function parameter. Remove or comment out the variable name to silence this warning. function setUserbyAdmin(address _address, string memory name,string memory surname,uint age) public payable onlyOwner{ ^————–^

Best Answer

You will see the same warning in Remix if you look at the compiler page.

The warning is quite clear: you have a variable which is not used anywhere in the function logic. It's not an error but the compiler is trying to help you to save gas and to make the function cleaner by removing the unneeded parameter. If you want you can just ignore the warning.

There is a curious feature that if you remove the variable name the warning disappears. But the function still has the same signature. I actually don't know why such a thing has been implemented.

Related Topic