I try to call my Solidity function:
function getVehicleDetails(string _vin) returns (string _vln, uint _year, string _make, string _model, string _colour) {
Vehicle vehicle = vehicles[_vin];
if (vehicle.year == 0)
throw;
_vln = vehicle.vln;
_year = vehicle.year;
_make = vehicle.make;
_model = vehicle.model;
_colour = vehicle.colour;
}
Here's the geth command:
instance.getVehicleDetails("vin_101",{from:web3.eth.accounts[1]})
returns
"0x6cf98ab5b77bfa0397ee6eaa046f85a133c5a3ef636c59a56b4308dc73fb20fd"
i.e. it keeps returning a tx receipt!
Here's how I create a vehicle:
function setVehicleDetails(string _vin, string _vln, uint _year, string _make, string _model, string _colour) owneronly {
Vehicle vehicle = vehicles[_vin];
if (vehicle.year == 0)
throw;
vehicle.vln = _vln;
vehicle.year = _year;
vehicle.make = _make;
vehicle.model = _model;
vehicle.colour = _colour;
}
I call this in geth with:
instance.registerVehicle("vin_101","vln_101",2004,"ferrari","convertible","black",{from:web3.eth.accounts[0],gas:4000000})
What am I doing wrong?
All I want to do is read the return values from getVehicleDetails and it just refuses to!
I'm on testrpc.
constantkeyword. So, I used "call" instead.instance.getVehicleDetails.call("vin_101",{from:web3.eth.accounts[0]})I'm figuring this out the hard way!!! – Eamorr May 27 '17 at 16:13callwon't help you.Callis similar tosendjust it doesn't create a transaction and publish it to the blockchain. There is no difference in the way call and send invoke the function. – Prashant Prabhakar Singh May 27 '17 at 16:18browser-solidity), there is a definite difference between using "call" and not using it. Without "call", no return params are returned - just a tx receipt. With "call", you get the parameters returned. One thing you could do is just use the "constant" keyword in your Solidity function. If you're usingbrowser-solidity, you don't have to worry about this nuance. Though I found this very confusing - code worked fine in browser-solidity, but not on a real blockchain... – Eamorr May 28 '17 at 09:44