0

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{ ^--------------^

1

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.

  • thanks but do you know how can I set my users using with setUsersbyAdmin function ? can you help me about this ? – Furkan Demirel Jul 2 at 13:36
  • just remove the first parameter, it's useless – Lauri Peltonen Jul 2 at 13:53
  • thanks for help :) I solve this – Furkan Demirel Jul 2 at 14:01
0

hey guys I solve this problem 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 {
    users[_address] = 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);        
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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