I am trying to call a Smart contract that is supposed to return an address. I have tried the contract in Remix and It all works fine. I am know trying to execute the same contract using We3JS.
To do so I call web3.eth.sendTransaction(), then I wait for the blocked to be mined by comparing transactionReceit.gasUsed < transactionMinedResult.gas. When the block is mined I try to access to the block by calling web3.eth.getBlock(blockHash); It all seems to work and after a few seconds I get my block data back, it looks like this:
{
"blockData":{
"difficulty":"2004806",
"extraData":"0xd783010509846765746887676f312e372e33856c696e7578",
"gasLimit":4712388,
"gasUsed":44328,
"hash":"0xdaba1b785abec44f369dd661f457f829acc12ba02ed3e096db71a63801b2e02f",
"logsBloom":"0x00000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000080000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000010000000000000000000000000000000000000000000000001000000000000000000000040000000000000000000000000200000000000",
"miner":"0x5e5fd76c0ddbf6e594c33cde0c3fa8627d84d116",
"mixHash":"0xc47e161dcf3f2c3d480bd7dfd5f1a8cbac45582d380d8203bd5a4949f4280fdf",
"nonce":"0x4ee6e771c2773b25",
"number":235186,
"parentHash":"0x5cd9b5db1c3e000faa45ab6e92dae2b678fd00eb84c179f77b4f7fdcf689d047",
"receiptsRoot":"0xa95a03ebe37e272941e71d357dc10dd57b64c7892bcd303c7cb4fdbd80281083",
"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size":783,
"stateRoot":"0x2b34eab5aa15aa6502785fb09ea9ae507306be88b0fb9317ab788bbcedd8e28c",
"timestamp":1492124244,
"totalDifficulty":"460326490665",
"transactions":[
"0xfb214080f50c9fae296b6ec928aeca9c2d3e3a15c33bd5a888845e0aff3950da",
"0x533638638b9f97b05916a039d0e9da7200f2a1b944cd36294c6c293f0ca064bd"
],
"transactionsRoot":"0xcc4c3f395caaf03b4a98d80cf5578b91fc33f078e4382539daf5824093402fd5",
"uncles":[
]
}
}
Like I said above my contract is returning an address, where can i find this returned data in the block data ?
EDIT 1
Here is the contract I am trying to call:
address[] public patients;
function getPatientAddress(uint id) public constant returns(address){
LogPatientAddress(patients[id]);
return patients[id];
}
Following the first answer it is indeed constant, therefore where is the data available from web3js ?
LogPatientAddress(patients[id])intending to keep a log of all calls made to it? Is there a reason you need to do this? – o0ragman0o Apr 14 '17 at 01:51mapping (uint => uint) public patientIds;will generate the getter functionfunction patientIds(uint _id) constant returns (uint)which will return the value to your client – o0ragman0o Apr 14 '17 at 01:57uint public patientIDsworks also. The point is that is one advantage of thepublickeyword. It exists as a function defined in the contracts ABI and so you call it like any other function in JSpId = k.patientIDs(someID)` (where k is you contract instance) – o0ragman0o Apr 14 '17 at 02:06