Skip to main content
Distributed Ledger StudioBlockchain for IoTExperimentsWorkspaces
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
BLOCKCHAIN FOR IoT · BC-M09
Blockchain for IoT

Smart contracts, lifecycle and gas

Dr. Mohammad Alja’afreh · Princess Sumaya University for Technology

CallGas meterReceipt
Design experiment & verify evidence →
BC-M09 · Laboratory mentorAsk about the current experiment, its algorithms or Python notebook.
Ask Dr. MohammadAdaptive practice

← Lecture-aligned module experiments · All blockchain labs · Setup wizard

Introduction

Scientific architecture · Smart contract lifecycle, gas and atomic rollback

Atomic EVM state transition — Transaction / valid sender & nonce; Execute / metered gas; Success? / exception or revert; Commit / valid writes & logs; Revert / discard writes; gas charged
Scientific concept map: Caller — Function and inputs; Execution — Contract instructions; Gas budget — Cost accounting; Failure / revert — Discard state writes; Receipt — Status and gas.

Scientific foundations and analytical reasoning

A state-changing contract transaction has a gas limit and effective price. Revert rolls back state but can consume gas.

Before operating the equipment or executing the program, derive the expected outcome using the required theoretical work in Experiment. Use the diagram to identify the variables and system boundaries.

BC-M09 · Academic orientation

Scope and objectives

Scope of the experiment

Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.

The focus of this experiment is to trace smart-contract deployment, invocation and state transitions. Students then interpret gas, successful execution and reversion, and explain why deterministic execution does not guarantee contract correctness. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.

Learning objectives

  • Trace smart-contract deployment, invocation and state transitions.
  • Interpret gas, successful execution and reversion.
  • Explain why deterministic execution does not guarantee contract correctness.
  • Identify the configured inputs (Lifecycle state; Call type; Initial contract state; Requested increment; Gas limit) and record the corresponding observed outputs with units where applicable.
  • Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.

Expected learning outcomes

On completion, students can trace smart-contract deployment, invocation and state transitions, interpret gas, successful execution and reversion, and explain why deterministic execution does not guarantee contract correctness.

Required deliverables

Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing explain why deterministic execution does not guarantee contract correctness. Separate predicted values from observations.

Prerequisite knowledge and related learning

Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to Solidity, Remix and access control.

Environment and experimental methodology

The listed browser model and experiment-specific local Python, Solidity or EVM workflow, where provided. Do not treat a model as a deployed ledger.

Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.

Scientific theory · Transaction gas and rollback

A smart contract transaction has a gas limit, which caps allowable execution work; gas used is the actual accounted work. The effective gas price determines the fee. A reverted execution can consume gas while rolling back contract state changes. Read-only calls and submitted transactions are different interfaces.

Worked example and engineering interpretation

A successful transaction using 21000 gas at 20 gwei costs 420000 gwei = 0.00042 ETH. A limit of 50000 gas does not imply paying for all 50000. Compare state and receipt for the successful and reverted teaching cases.

Engineering principles · additional worked teaching example

State-changing contract calls consume execution resources and may revert. A view call can be read locally without a transaction. Fee=gasUsed×effectiveGasPrice; 25000 gas at 12 gwei/gas costs 300000 gwei=0.0003 ETH.

From theory to experiment

Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.

Worked engineering reasoning and boundary conditions

Engineering reference configuration: Lifecycle state = deployed; Call type = write; Initial contract state = 10; Requested increment = 5; Gas limit = 50000; Configured execution gas = 42000; Effective gas price (gwei) = 20; Explicit execution revert = false. In the classroom model, Receipt = Success; Final state = 15; Gas charged = 42000; Fee = 840000 gwei. The explicit gas requirement is a teaching input. Actual gas is obtained from an EVM receipt. State machine with explicitly configured gas cost; not an EVM, network client or gas estimator.

Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.

Concept animation · independent state notebook

Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.

Smart contracts, lifecycle and gas: independent state notebook12345Calculated state 1StageSource / compilationObservationdeployed

Step 1 of 5 · Calculated state 1

Calculated state 1

Stage
Source / compilation
Observation
deployed

Teaching example only; inspect live calculations or real practical evidence separately.

How to investigate Smart contracts, lifecycle and gas

Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.

Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.

Experiment-specific guided practice

Objective: Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.

  1. Start deployed, write, state 10, increment 5, gas limit 50,000, required 42,000 and effective price 20 gwei. Verify state 15 and fee 840,000 gwei.
  2. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit.
  3. Restore limit and force an explicit revert; compare receipt, state and charged gas.
  4. Switch to read only (eth_call model): inspect returned value, no transaction fee and no state update.

Reference check: Read-only local call does not pay a transaction fee. Failed included transactions can consume gas without committing contract state.

Model boundary: Fixed illustrative gas costs, not measured EVM gas. Use actual receipts in Remix for precise costs.

Independent task and submission evidence

2. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit. Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.

Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.

TrialChanged settingFixed settingsPredicted resultActual observation / unitsEvidence / uncertainty
A: baselineReferenceRecordPredictRecordRecord
B: one changeRecordSame as APredictRecordRecord
A: repeatRestoreSame as APredictRecordRecord

Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.

Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.

Learning goals

  1. Explain the mechanism using the actual intermediate states in this experiment.
  2. Predict and verify the reference and modified conditions described below.
  3. Interpret the acceptance criteria and identify the limits of the model.

Module flashcards · 12 questions

Browse all 12 questions and explanations
How many Wei equal one ETH?

10^18 Wei.

What is a Gwei?

10^9 Wei.

Why meter computation?

It bounds execution resources and charges for included work.

Can a reverted transaction consume gas?

Yes. Failed execution may still consume gas, without committing reverted state.

What is the difference between gas limit and gas used?

The limit bounds execution resources; gas used is the actual metered consumption.

What is the fee formula used in this model?

Gas used multiplied by effective gas price in Wei per gas.

Does a local read require an included transaction?

No, a read may be evaluated locally with no paid transaction.

Why should actual gas be taken from a receipt?

The illustrative cost table is not an EVM execution measurement.

What fee does a local read-only call pay in this model?

No transaction fee.

How is a transaction fee computed from consumed gas and effective gas price?

Multiply gas used by effective gas price; convert the units consistently.

Can a failed included operation charge gas without updating state?

Yes. Reversion rolls back contract state, not all execution cost.

Why vary gas limit independently of price?

The limit bounds execution gas, whereas price determines cost per gas unit.

Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research