Smart Contract Costs – Who Gets Paid in Smart Contract Function Calls?

contract-invocationgasgas-pricesolidity

This is an extended question to What is "gas" and transaction fee in Ethereum?.

Who gets paid and how much does the caller pay?

Let's make some assumptions:

  • There is a function F which costs 1,000 gas;
  • There are 2 miners, M1 and M2;
    • Their gas prices are 1 GWei/gas and 2 GWei/gas respectively;
  • There is an external address A.

The questions are:

  • When a caller A invokes F, how much does A need to pay (ignoring data transfer fees)?
  • Is it the total (3 kGWei) or is it determined by whoever mines it first (1 kGWei or 2 kGWei)?
  • If M1 mines it first, will M2 just trust the result or will it do it all over again to check the correctness?
    • Then M2 should also get paid, right?
  • Will the result be stored in all full nodes, or just the miner nodes, or just the miner nodes that are "willing" to store it (with matching gas price)?
    • Then other nodes should get paid too?

Best Answer

A specifies a gas price.

M1 and M2 decide whether to mine A's transaction if the gas price is high enough. If A's gas price was 1.5 GWei/gas, then only M1 would choose to mine A's transaction (since M2 wants 2 GWei/gas).

A always pays 1000 (given F costs 1,000 gas) multiplied by the gas price it specified; miners cannot change the transaction fee A pays and can only choose whether to include A's transaction in a block.

Only the winning miner gets the transaction fee paid by A. Other miners and all other (full) nodes do have to verify the transaction and store its results: yes, it's unfair to them and part of the problem related to incentives and scalability.

More information, https://blog.ethereum.org/2014/02/01/on-transaction-fees-and-the-fallacy-of-market-based-solutions

For each individual transaction that a miner includes, the costs are borne not just by that miner, but by every single node in the entire network.