1. Gas

`GAS` A proxy measurement which does not change with the current price of ether

Gas is an abstract unit of measurement for estimating the work
to make a transaction and including it into the next block.

2. Paying for work

Paying for gas is paying for miners’ doing the work.

If you are willing to pay more for gas, miners will mine your transaction with higher priority.

This payment is what miners earn for their work in
addition to the fixed pay for every created block.

If insufficient funds, transaction fails with `out of gas` exception

3. Estimate `gas` consumption

some example operations:

A list of all EVM instructions + gas costs can be found in the yellow paper

Appendix G. Fee Schedule to be read with Appendix H.

4. Limits of estimation

Executing a contract might depend on:

  1. conditionals in the contract logic (…if/else)
  2. data a contract accesses and which is subject to change

=> in practice gas estimation happens via simulation

web3.eth.estimateGas({
   to: "0xc4abd0339eb8d57087278718986382264244252f",
   data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003"
}, (err, result) => console.log(result))

5. Calculate Price

When making a transaction you can set:

  1. How much ether you pay for every unit of gas
  2. and the maximum amount of gas you are ready to buy

gasCostTotal = gasUsed * gasPrice

6. Reduce cost to call the contract functions

  1. Reduce Expensive operations
  2. Use short-circuiting rules

=> DEMO TIME: Debugger Demo

7. Reduce cost of deploying contracts

  1. compilation optimizes code size, see:
  2. details optimizer, see:
    • e.g. removing useless code:
    function p1 ( uint x ){
      if ( x > 5)
        if ( x*x < 20)
          XXX
    }
    
  3. use ProxyFactory trick

=> DEMO TIME: ProxyFactory Demo

 

more information: https://ethereum.stackexchange.com/a/28848

8. How to make apps which use contracts

remix-IDE can be used to listen to transactions and debug them

(~ backend/admin/...)

(via: MetaMask/Mist/....)

Made with Slides.com