What is Gas?

Gas measures the work done or computational power spent in validating transactions. Validating blockchain transactions is important to maintain the integrity of the network. However, this requires computational power and tools from a distributed network of computers running nodes on the blockchain. Gas measures how much work is required to deploy a transaction node request and publish it securely.

See gas as the electricity/power in your locality measured in Watts or kW/h. You use a meter to check how much power is consumed at every given time. Usually, there is a structure designed to calculate gas payments just like there is for an amount of power (kWh) consumed at a time. The fee paid with respect to this gas is called a “gas fee.”

Cosmos ensures that the money spent to reward validators is accounted for, and those not spent are refunded after the transaction. During a transaction, Tx, a GasMeter, directed by the Context function, is used to track and record the amount of gas spent. Upon executing the transaction, the GasUsed (fn) is set and returned to the abci.ResponseDeliverTx (fn). If the gas as specified in the GasMeter runs out, the state change returns an error message.

Here’s how is a detail of how the Cosmos’ gas system works:

  • The user-provided amount of gas for Tx is known as GasWanted.

  • If GasConsumed, the amount of gas consumed during execution ever exceeds GasWanted, the execution will stop, and the changes made to the cached copy of the state won't be committed.

  • Otherwise, CheckTx sets GasUsed equal to GasConsumed and returns it in the result.

  • After calculating the gas and fee values, validator nodes check that the user-specified gas prices exceed their locally defined min-gas prices.

Read more on gas and gas fees here.

Last updated