1

I understand the difference between transaction costs and execution costs, but I don't understand two things:

  1. What does the "gas" readout in Remix refer to?
  2. How do I create an estimate of how much doing something will cost?

When I run a transaction in Remix, I get the following output when I click the down arrow for more details on the transaction:

Solidity Output

I thought that "gas" would just be a sum of transaction cost and execution cost, but that's obviously not the case. So what does this gas line mean?

In addition, using this information, how would I compute how much money (in dollars) it would take to have completed this transaction?

I know I can see how much gas costs here. (Currently at 114.43 Gwei.) Then, since there is 1 billion Gwei in an Ether, and the price of an Ether can be looked up here, I can figure out how much in dollars each gas costs.

But what numbers do I multiply by this cost to get the total cost of running something? Should I do (gas + transaction cost + execution cost) * gas price? Or just (transaction cost + execution cost) * gas price? Or does only the execution cost matter?

(Also note that I have read through the answers to this question as well, but they don't answer my question (1) and aren't very clear about my question (2). Thus, I have asked a new question.)

Pro Q
  • 113
  • 4

1 Answers1

0

EDIT: I believe I misunderstood your question; this is probably a better response:

What does the "gas" readout in Remix refer to?

The gas line is referred to the total maximum amount of gas provided with the transaction (you are including 80... gas to be used)

the execution is how much gas is effectively used of the amount provided; so in your example 80.... gas is probably too much compared to the real necessity (anyway the unused gas will be returned, so you are not paying the whole amount)


How do I create an estimate of how much doing something will cost?

in order to estimate your gas consumption there is a function called gasEstimate()

you can check an usage here: https://medium.com/truffle-suite/ethereum-gas-exactimation-1158a996eb8c

Here is a truffle example test:

const Optim = artifacts.require("Optim");

contract("Optim", () => { it("should have different gas", async() => { const O1 = await Optim.new();

    const method1 = await O1.method1.estimateGas(params);
    const method2 = await O1.method2.estimateGas(params);

    console.log("method1 cost: " + method1, "method2 cost: " + method2);
    assert(method1 < method2, "method 1 < method2");
});

});


On a broader context, to better understand what operations cost more than others:

here, as an example, (https://github.com/crytic/evm-opcodes) you can check that an ADD operation needs 3 gas.

so : more complex code = more gas needed

-- if you are well versed in math you can check the H.1 appendice in the ETH yellow paper

https://ethereum.github.io/yellowpaper/paper.pdf to identify which operations requires more or less gas


To know how much USD you are spending, you need to convert from ETH to USD gas_used * gas_price

the gas price is gwei (ETH) and fluctuates constantly, so you won't have a sure "carved in stone" answer (it depends on the network status);

Stormsson
  • 379
  • 1
  • 13
  • So the output from Remix isn’t helpful at all for estimating the dollar cost of running a function in my contract? – Pro Q Aug 31 '21 at 21:29
  • You also mention that “you are not paying the whole amount”. Where can I find the amount that I am paying? – Pro Q Aug 31 '21 at 21:31
  • I'll edit the answer to provide a more clear response; btw the execution is how much gas is effectively used of the amount provided – Stormsson Sep 01 '21 at 07:18
  • btw I am totally not sure about the transaction cost interpretation in the link you provided: 80 million gas is an enormous amount, i don't think a contract deployment costs as much. in my opinion that is the AVAILABLE gas sent with the transaction – Stormsson Sep 01 '21 at 07:43
  • Yes, I understood this from your answer (and from research done earlier), but I still need to know how much gas was actually used. If I don’t know that, I can’t make my estimate. What I gather from your answer is that 1. The gas output from remix is how much gas I originally put in, though excess will be refunded. That answers question 1. But since I don’t know how much was refunded, I’m still looking for an answer to question 2. – Pro Q Sep 01 '21 at 20:18
  • If the answer is “I can’t tell how much you were refunded from the information you gave me”, then I will accept. – Pro Q Sep 01 '21 at 20:21
  • 1
    the execution cost is the amount of gas that will be consumed – Stormsson Sep 02 '21 at 06:57