Let's take an example of a transaction where you want to transfer 0.1 ETH to your friend. The following are the values for the transaction fields you would have to fill while creating a transaction:
Field name | Value |
From | 0xff899af34214b0d777bcd3c230ef637b763f0b01 |
To | 0xc4fe5518f0168da7bbafe375cd84d30f64cda491 |
Value | 0.1 ether |
Gas limit | 30,000 |
Gas price | 0.000000021 ether (21 gwei) |
You can also refer to Chapter 4, Learning MetaMask and Remix, where we have demonstrated how to use MetaMask to initiate transactions.
Once the transaction is sent and confirmed on blockchain, you can see its status on block explorer (etherscan.io) as follows:
Let's calculate the values using these formulas:
- TxFeeMax = 30,000 * 0.000000021 = 0.00063 ether
- TxFeePaid = 21,000 * 0.000000021 = 0.000441 ether
- TxFeeReturned = 0.00063 - 0.000441 = 0.000189 ether
- GasUnused = 30,000 - 21,000 = 9,000 units of gas
- BalanceRequiredAtTransactionInitiation = 0.1 + 0.00063 = 0.10063 ether
Let's go through the preceding calculations. When you initiate the preceding ether transfer transaction, it must have a balance of 0.10063 ether. If the balance in your wallet is lower than 0.10063 ether, then you will not be allowed to initiate transactions and this will be rejected by the client itself as it's an invalid transaction.
If you have sufficient balance and the transaction is initiated, then, along with your transaction, the BalanceRequiredAtTransactionInitiation amount will be locked. So, in this example, 0.10063 ether is locked.
Now, your transaction is processed, 21,000 gas has been consumed in order to execute the transaction on the EVM, and the transaction executed successfully. As it consumed only 21,000 gas, it refunds 9,000 units of gas. This means 0.000189 ether will be refunded back to your wallet and you have paid 0.000441 ether for your transaction processing.
An ether transfer requires a fixed 21,000 gas limit per transaction. If you also include data along with the ether value, it may require a greater gas limit to execute the transaction.