0

I find this concept to be very confusing, when should I be using watch, call or get to listen to an event? how are they different and when should they be used?

var event1 = newInst.getSupplier({'OwnAdd': someaddr},{fromBlock:'latest, toBlock:'pending'}, function(error, result) {
    console.log("listening bro1");
    if (!error)
        console.log(result.args);
});

How will the output differ when I change the call or watch or get?

0

getSupplier - if it is a view or pure smart contract function will defer to the call (so they are the same) If there is a state change it will defer to sendTransaction

The call should return the value immediately from the blockchain - there is no mining involved.

watching or filtering will wait for an event to be added to the logs - if that event is being emitted by the smart contract. That is if you use watch on the filter.

getting the logs by means of calling get on your filter will returns the logs that match the filter.

more detail here: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods

0

call() is a read-only operation that returns a value but can't change the state. This behavior can be suggested by the contract itself. Have a look here: What is the difference between a transaction and a call?

sendTransaction() can change the contract state, does return a transaction hash but can't change the state.

Also, this might be helpful if the foregoing is impenetrable: https://blog.b9lab.com/calls-vs-transactions-in-ethereum-smart-contracts-62d6b17d0bc2

watch() is for event logs in contracts, not functions. Logs are an important aspect of contract design. Software clients can learn a lot about happenings inside contracts if the logs are well-designed.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.