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?

3 Answers 3


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 (...)


Well, If you can write such kind of code and deploy it ... Yes, it will work, but, the use case for such a contract that can only return static data form any source will be extremely limited.

And as far as I know, suppose you create such a contract, it cannot return anything(dynamic data related to something) as it has nothing inside the contract(say, mapping or arrays or structs).

here is an example:

pragma solidity >=0.4.22 <0.7.0;

contract sample {
 address user;
 constructor () public{
     user = msg.sender;
 function returnUser() public view returns(address){
     return user;

Think about it... range of use case of such codes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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