In The Crypto World, Miners Keep Timesheets

Within Ethereum applications we define the concept of gas. This is basically the unit that is used to measure the amount of work that is…

In The Crypto World, Miners Keep Timesheets

Within Ethereum applications we define the concept of gas. This is basically the unit that is used to measure the amount of work that is required to perform a single Keccak-256 hash, and where 30 gas consumed related to a single hash and 6 more gas for each 256 bits of data hashed.

In this way there is a motivation to keep contracts small, as they will be less costly. A sample contact which was been compiled has data and a gas value:

var supply = /* var of type uint256 here */ ;
var browser_market_sol_marketContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"findBalanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"sendCoin","outputs":[{"name":"sufficient","type":"bool"}],"payable":false,"type":"function"},{"inputs":[{"name":"supply","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"receiver","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"MoneyTransfer","type":"event"}]);
var browser_market_sol_market = browser_market_sol_marketContract.new(
supply,
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000c..4e067c3188f2b0029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})

Gas thus provides a way to define the fee that miners receive in performing operations on the blockchain. This differs from Bitcoin which only charges for the number of kiloBytes in a transaction. When it comes to the actual payment of the transaction fees, there is a payment of ether to the miners who create the blocks.

Ethereum transactions thus have a fee associated with them. If the fee is too low, then the miners will not process the transaction. When gas is consumed it is paid to the miner, and cannot be recovered back. If the transaction fee is set too high, there are likely to be many eager miners who are keen to profit from the high fee, and your transaction is likely to be prioritized. Overall, though, miners only charge for the work they have done, and they will return back any excess gas which they have not used.

A miner can decide whether it needs to change the use of gas according to the price of gas varying. This overcomes the changes in transaction fees that happen in Bitcoin. In Ethereum, just like Bitcoin, there is a block limit, so you’ll end up paying more if you overspill into another block (which means you should be efficient with your code and data).

The gas price per transaction aims to overcome denial of service and infinite loops, and where 0.00001 Ether or 1 Gas is used to execute a line of code. If there is not enough Ether, no transaction will be performed. It also aims to make code designers efficient and not use waste bandwidth and CPU utilization.

So, in a crypto world, even miners keep timesheets!