0

a Consensys factory class has this method:

//verifies if a contract that has been deployed is a Human Standard Token. //NOTE: This is a very expensive function, and should only be used in an eth_call. ~800k gas

function verifyHumanStandardToken(address _tokenContract) constant returns (bool) ...

Do certain constant methods use gas? Don't they just query the blockchain on the local node?

Can somebody clarifies this? Thanks.

1

This is not what constant means. A constant function means that your node does not need a transaction to run it - because it does not alter any state. However, if your constant function is called within a transaction - it will cost gas as part of a transaction. What you could do with constant code is running it outside (e.g. before) a transaction on your node. Then it will not cost any gas.

1

You should read Edmund's answer on this topic.

Constant functions can be run by your node for free.

If however you want them to be run as part of a transaction, they need to be run on chain (which costs gas). This is because Ethereum is a trustless ledger. If it were not run on chain, the result could be tampered with.

  • Check the contract: github.com/ConsenSys/Tokens/blob/master/contracts/… line 19, as you can see, the function is intended to be called independently. In such case, should cost anything right? I guess my real question is, under which case you would call this method in chain transaction? why? – John Smith Aug 19 '17 at 20:03
0

A constant function is expected to keep the state of the contract constant. There should be no point (although permitted) in sending a transaction to the contract to execute a constant function.

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