Given the following transaction parameters, what is the total cost in Ether for this transaction?
Gas limit: 21000
Gas price: 50 Gwei (1 Gwei = 10-9 Ether)
gas_limit = 21000 gas_price_gwei = 50 gas_price_ether = gas_price_gwei * 1e-9 total_cost = gas_limit * gas_price_ether print(total_cost)
Multiply gas limit by gas price converted to Ether.
Gas price in Ether = 50 * 10-9 = 0.00000005 Ether.
Total cost = 21000 * 0.00000005 = 0.00105 Ether.
Which statement correctly describes the relationship between gas limit and gas price in a blockchain transaction?
Think about how much gas you allow and how much you pay per gas unit.
Gas limit sets the max gas units a transaction can consume.
Gas price is the cost per gas unit in Ether.
What error does the following code produce when calculating transaction fees?
gas_limit = 30000 gas_price = '20' total_fee = gas_limit * gas_price print(total_fee)
Check the data types of variables before multiplication.
No TypeError occurs because in Python, multiplying an int by a str repeats the string instead of performing numeric multiplication. The output is '20' repeated 30,000 times.
What is the output of this code snippet?
def calculate_fee(gas_limit, gas_price_gwei):
gas_price_ether = gas_price_gwei * 1e-9
return gas_limit * gas_price_ether
fee = calculate_fee(50000, 100)
print(f"{fee:.6f}")Multiply gas limit by gas price converted to Ether.
Gas price in Ether = 100 * 10-9 = 0.0000001 Ether.
Total fee = 50000 * 0.0000001 = 0.005 Ether.
Which is the main reason blockchain networks require gas fees for transactions?
Think about why networks charge fees for running code.
Gas fees prevent spam and ensure users pay for the computational work their transactions require, helping allocate resources fairly.