I have a question about gas price as it relates to sending a transaction - is there a reason why that field is required? If I were to specify more than the cost of the transaction in the gasPrice field, the sender gets refunded the difference, correct? So why not just deduct the exact cost of the transaction from the sender's balance on the backend when processing the transaction?
Hey there! :)
In fact there are 2 different fields:
GasPrice: Determines how much gas you get per egld. Has a minimum and you should never need to bother with it :)
GasLimit: This is what I assume you're talking about. It defines the maximum amount of gas a transaction is allowed to take.
As to why you need to specify the gas limit there are several reasons.
- Security. You always want to be in charge of your egld. It would be bad if a transaction from a (malicious or badly programmed) dapp could strip you out of all of your egld without you having any chance to know that beforehand or avoid that.
- Technical. A blockchain needs to limit the amount of transaction that can be executed in one block, otherwise you couldn't guarantee block times and consensus would be (nearly) impossible to reach. It does limit the transaction by using the gasLimit provided in the transaction. Max gas limit per block is 15b.
Hey there! :) In fact there are 2 different fields: GasPrice: Determines how much gas you get per egld. Has a minimum and you should never need to bother with it :) GasLimit: This is what I assume you're talking about. It defines the maximum amount of gas a transaction is allowed to take. As to why you need to specify the gas limit there are several reasons. - Security. You always want to be in charge of your egld. It would be bad if a transaction from a (malicious or badly programmed) dapp could strip you out of all of your egld without you having any chance to know that beforehand or avoid that. - Technical. A blockchain needs to limit the amount of transaction that can be executed in one block, otherwise you couldn't guarantee block times and consensus would be (nearly) impossible to reach. It does limit the transaction by using the gasLimit provided in the transaction. Max gas limit per block is 15b.