I am trying to access data stored in a contract from web3. I have managed to do so with a custom get function, however from what I have read online, every public variable has a built in get and set function created by Solidity. I also understood that it has somethign to do with callbacks, but I am not sure how to implement it in my js code. Here is what I have done to get my data so far:
Solidity Contract
contract OrganizationObject {
struct organizationDetails {
string name;
string vat;
string headquarterAddress;
}
organizationDetails public details;
address[] public staff;
function OrganizationObject (string name, string vat, string headquarterAddress){
details.name = name;
details.vat = vat;
details.headquarterAddress = headquarterAddress;
}
function getDetails() public constant returns (bytes32[], string, string, string){
return (order, details.name, details.vat, details.headquarterAddress);
}
function addStaff(address x){
staff.push(x);
}
}
web3
app.post('/api/getOrganisationDetails', stormpath.authenticationRequired, function(req, res){
var rawString = req.user.customData;
var stringJson = JSON.stringify(rawString);
var customData = JSON.parse(stringJson);
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(customData.ethereum_provider));
var address = req.body.address;
// creation of contract object
var MyContract = web3.eth.contract(abi.abiOrganisationObject).at(address);
var details = MyContract.getDetails();
console.log(details);
res.end(details).status(200);
});
I think the better solution would be to use the getter function from solidity, I have tried like this:
app.post('/api/getOrganisationDetails', stormpath.authenticationRequired, function(req, res){
var rawString = req.user.customData;
var stringJson = JSON.stringify(rawString);
var customData = JSON.parse(stringJson);
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(customData.ethereum_provider));
var address = req.body.address;
// creation of contract object
var MyContract = web3.eth.contract(abi.abiOrganisationObject).at(address);
var details = MyContract.details();
console.log(details);
res.end(details).status(200);
});
But it seems to want an argument in the MyContract.details(), which i assume is a callback. What should I do to be able to access the data stored inside MyContract.details ?