# Gas

By [CryptoVincent](https://paragraph.com/@cryptovincent) · 2022-10-16

---

### How much ether do you need to pay for a transaction?

You pay `gas spent * gas price` amount of ether, where:

`gas` is a unit of computation

`gas spent` is the total amount of `gas` used in a transaction

`gas price` is how much ether you are willing to pay per `gas`

Transactions with higher `gas price` have higher priority to be included in a block.

Unspent gas will be refunded.

### Gas Limit

There are 2 upper bounds to the amount of gas you can spend

`gas limit` (max amount of gas you're willing to use for your transaction, set by you)

`block gas limit` (max amount of gas allowed in a block, set by the network)

In the below code we have a function with a infinite loop, it run until all of the gas are spent and transaction fails.

![](https://storage.googleapis.com/papyrus_images/4e277df61e53c995ac44dfd93b6346e3251389433ec475f12ce4d0ba6b42e635.png)

---

*Originally published on [CryptoVincent](https://paragraph.com/@cryptovincent/gas)*
