rBTC Gas Fees: Optimizing Transaction Costs
Gas is the internal pricing for running a transaction or contract. When you send tokens, interact with a contract, send rBTC, or do anything else on the blockchain, you must pay for that computation. That payment is calculated as gas. In Rootstock, this is paid in rBTC.
What is gas?
There are four important concepts:
- Gas price: The cost of the operation.
- Gas limit: The maximum gas the operation can afford. It's an upper limit the user sets to prevent losing gas.
- Total gas: The gas the operation consumed. Also referred to as gas used.
- Unit: Gas is paid in rBTC.
Let's start with a simple analogy: A car.
To drive a car you need gas. Gas price is the money you pay for each gallon. Gas limit is the max amount of gas you accept to consume, the gas you charge. The total gas is the amount you've spent at the end of the trip. You can calculate the total gas and set an appropriate gas limit so that your trip does not expend more than expected.
Transactions are quite similar:
Gas price is the price you set for operations. The gas limit is the maximum price you are going to pay for the transaction when operated. Then, when transaction is executed, the total gas is the price you finally pay.
Gas is the fee collected by the miner who mines the block that includes the transaction.
The resulting fee is:
fee = totalGas * gasPrice
How do I choose an appropriate gas price and limit?
If you want to spend less on a transaction, you can do so by lowering the amount you pay per unit of gas (gas price). Similar to Bitcoin, the price you pay for each unit increases or decreases how quickly your transaction will be mined.