2

The web3.js documentation states that with a contract method, call vs. transaction is chosen automatically:

Contract Methods

// Automatically uses call or sendTransaction based on the method type
myContractInstance.myMethod(param1 [, param2, ...] [, ...]);

*edited for brevity

I have tested two ways to call a function that does not mutate anything

1.testInstance.testfunc(param1, {from:eth.accounts[0]}) 2.testInstance.testfunc.call(param1)

Events are being issued with option 1 only, so I know that web3.js is choosing sendTransaction(). I expected it to automatically choose a call(), because the function doesn't change any state.

How does web3.js determine which to use?

carver
  • 6,381
  • 21
  • 51
standup75
  • 173
  • 1
  • 1
  • 6
  • It is a transaction, it can modify the contract state and generate events. The 'automagically determine' doesn't work sometimes. 2. It is a call it cannot modify contract state and will not generate events.
  • – Ismael Sep 01 '17 at 16:31
  • Thanks for clarifying your question; I think it is covered by Solidity constant. – eth Sep 02 '17 at 05:39