1

The code below does not set the simpleStorage instance's value to 55, but identical code works when the contract is not generated via a factory

enter image description here

  • It's better if you can post the code as a text than posting a screenshot – Achala Dissanayake Jan 20 '18 at 13:20
0

You are using .call which runs locally (doesn't broadcast to the network or change the state of the contract) so basically it won't create a contract

If you have a function that is marked as pure/constant/view, then using .call or not using .call doesn't matter; the function will return to you whatever you specified as the return value in your code.

If your function is not pure/constant/view then you should only use .call if you want to test whether the function will succeed or not, in this case .call will return true or false. If you don't use .call (i.e. just the function name); you will get a transaction object and you can get the new contract address from the log (which will be part of that transaction object), if you use functionName.sendTransaction you will get a transaction hash (not a transaction object). So the difference between using functionName and functionName.sendTransaction is that the first one will return a Promise which is a transaction object, but the Promise will resolve after the transaction is mined, the second case (.sendTransaction) will immediately return a transactionHash which you can use in getTransactionReceipt to check transaction status and contract address after the transaction has mined.

Just to summarize :-) using .call with a non pure/view/constant function will not modify the state, that's why the value wasn't set to 55; your function ran locally (it didn't broadcast to the blockchain, so no transaction, so no verification/mining, so no state change)

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.