0

I am trying to get the data returned by a smart contract on my private blockchain using web3js. I have found this function "web.eth.getBlock" which seems to do just that but everytime I call it I get something like this:

{
   "blockData":{
      "difficulty":"1938572",
      "extraData":"0xd783010509846765746887676f312e372e33856c696e7578",
      "gasLimit":4712388,
      "gasUsed":90000,
      "hash":"0x8a9abf75893cb0d3cdee7929b72a1d49363c71a10bb3748f2497dc8f0d3b5f34",
      "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "miner":"0x5e5fd76c0ddbf6e594c33cde0c3fa8627d84d116",
      "mixHash":"0xb52eb30a24abb25db75c1b91d83e55ce24dc033feb4698c419c91f2c495c20e1",
      "nonce":"0x31ada456b5f1989d",
      "number":222300,
      "parentHash":"0x08cd6982bf1d525e5b4f3f1576b4034a7ead0338e1b0ac11c9d04a631606556a",
      "receiptsRoot":"0xf81cb161e80846e78c6db389446e4d6a28a78f7e7409b128dfe761fd74d7703e",
      "sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
      "size":812,
      "stateRoot":"0xd1b1a0517fca5af823ce25f2e9d06c6d332ffec30dbd20feb09eb832f86473e3",
      "timestamp":1491941461,
      "totalDifficulty":"435348944544",
      "transactions":[
         "0x1ea0d74a01405ab4654dce574cd807ff0d2ca8a9f2b4f467210b1f09c265b82a"
      ],
      "transactionsRoot":"0x741c94b7afd5600f6285bd3f7013762a65a99d55ef1d51d50a6333969e0ccafd",
      "uncles":[

      ]
   }
}

According to the manual and this question my block has been corectly mined and my contract did not error. But my contract is supposed to return an address, where can I find this address in the JSON above.

Here is what my contract does:

function createPatient(bytes32 firstName, bytes32 lastName, uint height, uint weight, bytes32 dob) returns (address){
    PatientObjects newPatient = new PatientObjects(this, firstName, lastName, height, weight, dob);
    LogCreatedPatient(newPatient);
    patients.push(newPatient);
    return newPatient;
}

EDIT

After further reading it turns out that my contracts actually errors, I have compared the gas and the gasUsed (from getTransactionReceipt) and indeed it fails.

I however do not understand why or where it could error. I also assume that the error should therefore be contained in the block ? Is there anyway to retrieve this error from the block data ?

I have tried to execute my contracts using Remix and it all works fine, what could be the issue here ?

EDIT 2

I have tried to add constant and public to my contract definition, and I still get the same problem:

{
   "blockHash":"0x621e3a58b08f005f56e464e85752e8617c0e1225f5704c0d25b5d9876871d12a",
   "blockNumber":222655,
   "from":"0x5e5fd76c0ddbf6e594c33cde0c3fa8627d84d116",
   "gas":90000,
   "gasPrice":"20000000000",
   "hash":"0x9ab60bd27432d5125990c468bcfeb8701f1e1f4477256dc940f92e329a0b78f1",
   "input":"0x35abf6826800000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000008382f332f32303137000000000000000000000000000000000000000000000000",
   "nonce":31,
   "to":"0x4549adb2c70bebd7656bbee5406ecd9aaeb4a585",
   "transactionIndex":0,
   "value":"0",
   "v":"0x1b",
   "r":"0x90c64baf271205e3977c1ceab7aeb4f57a94d102c77381d406b00d0b0f030492",
   "s":"0x697b02a73958e82993889f368d6e18a708e65edc24810ea01abe3414fba07527"
}

and my getTransactionReceipt:

{  
   "blockHash":"0x621e3a58b08f005f56e464e85752e8617c0e1225f5704c0d25b5d9876871d12a",
   "blockNumber":222655,
   "contractAddress":null,
   "cumulativeGasUsed":90000,
   "from":"0x5e5fd76c0ddbf6e594c33cde0c3fa8627d84d116",
   "gasUsed":90000,
   "logs":[  

   ],
   "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
   "root":"0xb29152d8a7145b21227d7fe731ebf8813c6915f182c785b5ebc819c7fa7cad5e",
   "to":"0x4549adb2c70bebd7656bbee5406ecd9aaeb4a585",
   "transactionHash":"0x9ab60bd27432d5125990c468bcfeb8701f1e1f4477256dc940f92e329a0b78f1",
   "transactionIndex":0
}

I can see that gas and gasUsed are the same value i therefore assume that the execution has failed.

0xtuytuy
  • 599
  • 1
  • 6
  • 21
  • 1
    I'm not sure, but I think you need to add constant before returns. This might explain why you have a difference between gasUsed and gas. – FrenchieiSverige Apr 11 '17 at 21:19
  • I am trying, what is the point of adding constant ? I also saw that you can add public, what is the use of these 2 ? – 0xtuytuy Apr 11 '17 at 21:21
  • Sorry, are you trying to deploy your contract, or call a function of an already deployed contract? In either case 90000 gas may not be enough and you may need to specify a greater amount, e.g. `k.func(arg, {from: eth.coinbase, gas: 300000}) – o0ragman0o Apr 12 '17 at 02:09
  • I'm going to try later, I am trying to execute a contract that is then creating another contract with the data parse to it, indeed the gas might be too low ! thanks for the advice ! – 0xtuytuy Apr 12 '17 at 07:48
  • @o0ragman0o thanks it works fine ! So I am able to mine the transaction and the the block back, but I am not sure on how to get the actual data returned by my contract out of the block. The JSON returned by web3.eth.getBlock(blockHash); is full of stuff and none of it seems to be the actual data... – 0xtuytuy Apr 13 '17 at 23:05

0 Answers0