Sorry, new here. I look up everywhere but couldn't find an answer. Got these 2 simple functions. Can anyone explain why if i add "view " in the setUser function (first one) the other function Getuser is not working anymore

pragma solidity ^0.4.24; contract SalaryInfo { struct User { uint salaryId; string name; string userAddress; uint salary; }

User[] public users;

function set_User(uint _id, string _name, string _address, uint _salary) public view returns(uint) {
    users[users.length-1].salaryId = _id;
    users[users.length-1].name = _name;
    users[users.length-1].userAddress = _address;
    users[users.length-1].salary = _salary;
    return users.length;

function get_User(uint _id) public view returns(uint, string, string, uint,uint) {
    return(users[_id].salaryId, users[_id].name, users[_id].userAddress, users[_id].salary, _id);


  • Do you understand the purpose of view? Do you know what it is used for? I'm assuming that if you chose to add it, you must have a reason for that, and I'm wondering what that reason is. You may want to study Solidity before trying "random stuff". – goodvibration Jan 13 at 9:20
  • Totally agree. I'm sorry. Any books or tutorial you would suggest? – Gabriele Jan 13 at 10:31

Your Answer

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

Browse other questions tagged or ask your own question.