0

Hey guys I had a problem with my return function

here's my smart contract :

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  onlyOwner {
    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);        
}

}

and my web3.js code is here :

var getUserFunction = function(cb,_contractAddress = contractAddress, _jsonFile = JSONFile){
    var abi = JSONFile.abi;

    var contract = new web3.eth.Contract(abi,_contractAddress);

    contract.methods.getUser().call().then(function(data){
        cb(undefined,data);
    }).catch(function(err){
        cb(err,undefined)
    });

}


module.exports.getUser = getUserFunction;

and I call my function at orchestra.js. here's the code :

API.getUser(function(err,_data1,_data2,_data3){
    data1= _data1;
    data2=_data2;
    data3=_data3
    if(err){
        console.log(err);
        return;
    }
    console.log(data1,data2,data3);
}, '0xDeDbB36387f42FEB764056d1D52391F0A6B15D04',//contractaddress
require('./build/contracts/NewHello.json'));

I see 2 errors on my terminal

{ Error: types/values length mismatch (count={"types":1,"values":0}, value={"types":[{"name":"_address","type":"address"}],"values":[]}, version=4.0.29)

anyone can help me please ?

  • 1
    Comments are not for extended discussion; this conversation has been moved to chat. – eth Jul 5 at 0:12
0

the problem is my get function takes a parameter just modify this :

var getUserFunction = function(cb,_contractAddress = contractAddress, _jsonFile = JSONFile){
var abi = JSONFile.abi;

var contract = new web3.eth.Contract(abi,_contractAddress);

contract.methods.getUser('0xF15372bcF1FdD963Ea5514Dc96432Da8e795A8de').call().then(function(_data){
    cb(undefined,_data);
}).catch(function(err){
    cb(err,undefined)
});

}

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.