Basically you don't need to pay fee for contract call, but if a contract method does lots of work, you need to add gas in contract call to prevent DoS attack like this:
contract.method.call({gas: 1000000000})
Who gets this fee?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityBasically you don't need to pay fee for contract call, but if a contract method does lots of work, you need to add gas in contract call to prevent DoS attack like this:
contract.method.call({gas: 1000000000})
Who gets this fee?
"Call" is an overloaded term because it is one form of invoking a contract (see What is the difference between a transaction and a call?) and it depends where the invocation is performed, in relation to the Ethereum Virtual Machine (EVM).
The question's contract.method.call({gas: 1000000000})
deals with web3.js, which is outside of Solidity and the EVM.
The web3.js API is web3.eth.call and is what's used for Solidity constant
functions.
No one gets the fee because the "dry run" invocation is local to the node that web3.js is connected with: the network and miners do not know anything about this invocation.
However, even though the invocation is local, gas is still "used" and it is still possible to run Out of Gas or (self) "DoS" when invoking a Solidity constant function. For example, as explained in Can Solidity constant functions be arbitrarily complex?, Geth "only" provides local invocations with 50 million gas:
if gas.Cmp(common.Big0) == 0 {
gas = big.NewInt(50000000)
}
To avoid a "self DoS", try more gas like contract.method.call({gas: 999000000})
A more accurate reason why no one gets the fee is that gas is metering, and metering is different from fees, excerpt:
In Bitcoin, metering is done with bytes: the number of bytes in the transaction. In Ethereum, computation also needs to be metered because a small amount of code could still be a program that runs forever. Metering computation is one of the reasons for gas. But having gas doesn’t mean requiring fees.
For example, in a private chain each account could have X gas per day, or each account could have Y gas per transaction, or some other scheme. On the flip side, having fees doesn’t mean requiring gas: fees can be based on different metering, such as bytes. Security in a public blockchain requires both gas and fees, while the alternatives are more applicable to private chains (for example, a scheme where each account has X gas per day can be Sybil-attacked in a public chain where anyone can create an account).
A contract invocation with a web3.eth.call is still metered, even though there's no resulting fee, and that's why gas is still involved.
In Solidity, call
is a different beast altogether and is a low-level feature for a contract to send another contract a message, as explained in
What does Solidity's "call" function mean?
One thing to note is when .gas
is used, for example:
contract.call.gas(1000)(bytes4(sha3("methodName()")))
it means that the subcall invocation to methodName
will be limited to 1000 gas: it does not mean provide 1000 more gas to methodName
.
If the Solidity is being executed in the context of a "dry run" local invocation, then the transaction fee goes to nobody. If the Solidity is being executed in a transaction, the fee always goes to the miner of the block, even if there is an Out of Gas or execution error of any kind.
In the case that the transaction executes successfully, the actual fee goes to the miner that solves the block. To avoid redundancy, I'll just point to some details here: How do Ethereum's transaction fees compare to Bitcoin?. The take-away here is that the fee will not be 1000000000 in most cases, but it won't exceed it.
In the case of execution error, the gas is destroyed forever, so no one receives it.
It also bears mentioning that in the case of "call" (versus sendTransaction), the execution will be local and it won't cost gas, so in the end, the caller will still have the gas that was pledged. Using "call" is common for read-only operations that won't change state because it's faster and it's free.