From the web3 documentation on MyContract.method.call()
If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices:
Therefore you should use ES6 Object Destructuring Basic Assignment like so:
let {a, b} = await test.methods.getAandB(x).call();
Be careful: for this basic assignment from object destructuring you need to name the variables identically to the returned object keys -> a and b.
I am not sure if you should call it let {a, b}
or let {x,y}
. You should actually clean up your code here first. Your code should not have different variable names inside the return statement as compared to the variable names you return from inside the function block. Maybe like so:
contract Test{
function getAandB(uint x)
public
view
returns ( uint a, uint b )
{
a = x * 2;
b = x;
}
}
I have not tested your code using this, but I used it in similar code before and it worked well for me.
Albeit it is a bit pointless to just return the parameter passed to the function.