What if i make a smart contract that does modify the state, but the all its functions are constant.(it will still compile) It means that i can use my smart contract for free without paying for the gas. Wouldn't this be a lose to the miners? How does Ethereum handles this situation?


Yes, you can. Calling constant function doesn't create transaction. Your client just computes result locally.

However, constant functions can not change state (because they're constant)


You cannot change contract state without a blockchain transaction.

The reason it still compiles is because the Solidity compiler does not yet figure out with 100% accuracy which functions modify contract state. When I try to compile it, I do get this compiler warning:

Warning: Function declared as view, but this expression (potentially) modifies the state (...)

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.