When is Ethereum gas fee calculated during execution of contract. I was wondering if i take out flash loan and if the trade happened to be profitable, will the profit be able to offset transaction fee or I would have to pay upfront?
1 Answer
When you create a transaction you set two parameters:
gas
: Maximum amount of gas to be usedgasPrice
: Price to pay for each gas unit
To execute the transaction your account needs to have at least gas * gasPrice
ether.
Before executing your account is charged with gas * gasPrice
.
After the transaction has completed its execution unused gas and refunded gas are returned to your account.