"call" or "sendTransaction"

kenmazsymakenmazsyma tokyoMember Posts: 13
Hi, all.

I'm trying to use following simple contract via ethereum.js.

contract {
  uint data;
  function set(uint a) returns (uint ret) {
    data = a;
    return 1;
  function get() returns (uint ret) {
    return data;
There are two ways of ‎ calling set function.
‎The first one is eth.call
The second one is eth.sendTransaction.

Besause eth.call doesn't create transaction, it doesn't set data member.

Because eth.sendTransaction doesn't call function immediately, it can't get return value.

Is there no way to fullfill the above two problem?

Is it nessesary to call both? ‎


  • chrisethchriseth Member Posts: 170 ✭✭✭
    edited March 2015
    Using a transaction is the only way to achieve persistent calls. Since it is necessary to achieve consensus on any persistent modification of the state, this is much more complicated than just modifying a variable in a database:
    1. The user could decline your transaction
    2. Your client could go offline and you transaction is not transmitted to the network
    3. Your transaction could be rejected by miners due to various reasons
    4. It can even happen that you receive a block that contains your modification but later on, this modification is reverted because you ended up in a fork that was switched away from.

    So to sum up: Use events or other means to listen to modifications to the blockchain to check whether the change you wanted was included, but do not rely on them to always move forward.

    If your application is a simple reactive user interface, it should be quite easy to do.
  • kenmazsymakenmazsyma tokyoMember Posts: 13
    The purpose of to get return value is to listen to modifications to the blockchain to check.

    I understand it is necessary to switch the way of thinking to blockchain based from existing object-oriented language based.

    First of all, I’m going to try using Events.

    Thank you for your attentive comment :)
  • drcodedrcode Member Posts: 62 ✭✭
    FYI There are issues open in the ethereumjs github that delve into the various aspects of this issue, such as: https://github.com/ethereum/ethereum.js/issues/131
Sign In or Register to comment.