7

I have deployed:

contract test { 
      function multiply(uint a) returns(uint d) { 
               return a * 7;
      }
}

I can call the contract with "eth_call" :

mpsp@ubuntu-slave2:~$ curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to": "0x8e6f99f04148b1fb918cde7e44a94375f94dc745","data":"0xc6888fa10000000000000000000000000000000000000000000000000000000000000007"},"latest"],"id":1}'

the output is:

{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000031"}

But when I used "eth_sendTransaction" to invoke the contract and after mining, I used "eth_getTransactionReceipt" to get the result, and contract seemed not to be invoked. Here are my steps:

eth_sendTransaction

run:       mpsp@ubuntu-slave2:~$ curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0xc60ec7c68d47814288bdfdaa71b88ff922d735a7","to":"0x8e6f99f04148b1fb918cde7e44a94375f94dc745","gas":"0xC350","gasPrice":"0x1388","data":"0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"}],"id":1}'
outputs:   {"jsonrpc":"2.0","id":1,"result":"0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd"}

eth_getTransactionReceipt

run:        curl http://10.10.67.217:8545 --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd"],"id":1}'
outputs:    {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x26e23d45caf0c57159e88d9835c573a79f59a4fad0e7a7d70ea7a49780d14448","blockNumber":"0xc3a1","contractAddress":null,"cumulativeGasUsed":"0x5449","from":"0xc60ec7c68d47814288bdfdaa71b88ff922d735a7","gasUsed":"0x5449","logs":[],"root":"c42b14419677df59e3f593fccf03ea28f65bbd8927dcc9239dad6e77eb85f1a3","to":"0x8e6f99f04148b1fb918cde7e44a94375f94dc745","transactionHash":"0xcff6d91d1693abe876c25ba03a58bc6ca693078b3a90e836f656e0dddb08a4cd","transactionIndex":"0x0"}}

logs was empty in eth_getTransactionReceipt outputs.

Do you have some suggestions ?

Thank you!

Panda
  • 153
  • 1
  • 5

2 Answers2

5

The test contract is not emitting an Event, that's why there's no logs. Return values are not automatically included as a log.

Try:

contract test { 
      event R(uint x);
      function multiply(uint a) returns(uint d) { 
               R(a * 7);
               return a * 7;
      }
}

In case that doesn't work, you might need to bump up the gas (you have around 28,423 gas left).

eth
  • 85,679
  • 53
  • 285
  • 406
  • I tried and it worked,thanks a lot! Is there anyway I can get the calculation by using eth_sendTransaction without log – Panda Jun 07 '16 at 03:44
  • The return value can be obtained via eth_call; or another contract and see http://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call for more information. – eth Jun 07 '16 at 04:40
2

In addition to using events, if what I really want to do is just to generate log entries in the transaction receipt, I sometime find it simpler to call the "low-level" Solidity logging functions directly:

log1( value, 'log_topic');

will create a log entry containing value with the topic "log_topic".

log2(value,topic1,topic2) allows you to create an entry with 2 topics, and so on.

Link to Solidity documentation

jimkberry
  • 1,306
  • 11
  • 11
  • it's much simpler ,thank you ! if I don't generate log entries,is there anyway I can get the calculation of the contract? – Panda Jun 07 '16 at 03:59
  • You can write it to a contract storage variable after calculating and then later read it directly using eth_call(). Writing it to a variable will cost more gas than writing a log entry, but reading it from the contract using call() is way simpler and costs no gas. – jimkberry Jun 07 '16 at 14:27