0
0
Blockchain / Solidityprogramming~10 mins

Smart contract concept in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Smart contract concept
Start: Deploy Contract
Contract Stored on Blockchain
User Sends Transaction
Contract Code Executes
Check Conditions
Update State
Emit Events
Transaction Complete
This flow shows how a smart contract is deployed, then how it runs when a user sends a transaction, checking conditions and updating state or rejecting the transaction.
Execution Sample
Blockchain / Solidity
contract SimpleStore {
  int storedData;
  function set(int x) public {
    storedData = x;
  }
  function get() public view returns (int) {
    return storedData;
  }
}
A simple smart contract that stores a number and lets users set or get it.
Execution Table
StepActionInputState BeforeState AfterOutput
1Deploy contractN/ANo contractContract deployed with storedData=0N/A
2Call set(42)42storedData=0storedData=42Transaction success
3Call get()N/AstoredData=42storedData=42Returns 42
4Call set(100)100storedData=42storedData=100Transaction success
5Call get()N/AstoredData=100storedData=100Returns 100
6Call set(-1)-1 (invalid)storedData=100storedData=-1Transaction success (no check in code)
💡 Execution stops after last transaction; smart contract runs code on each call updating or returning state.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6
storedData04242100100-1
Key Moments - 3 Insights
Why does calling get() not change storedData?
Because get() is a view function that only reads storedData without modifying it, as shown in execution_table step 3 and 5 where state before and after remain the same.
What happens if we try to set a negative number?
In this simple contract, there is no check for negative numbers, so storedData changes to -1 anyway (step 6), but in real contracts you should add checks to prevent invalid data.
Why does the contract keep its state between calls?
Because the contract is stored on the blockchain and its variables like storedData persist between transactions, as seen in variable_tracker showing storedData values after each step.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of storedData after step 4?
A42
B100
C0
D-1
💡 Hint
Check the 'State After' column in row for step 4 in execution_table.
At which step does the contract return the value 42?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'Output' column in execution_table for the step returning 42.
If we add a check to reject negative numbers in set(), what would happen at step 6?
ATransaction is rejected, storedData stays 100
BstoredData changes to -1
CContract crashes
DstoredData resets to 0
💡 Hint
Refer to key_moments about input validation and execution_table step 6.
Concept Snapshot
Smart contracts are programs on the blockchain.
They run when users send transactions.
They store and update data persistently.
Functions can change state or just read it.
Transactions succeed or fail based on code logic.
Full Transcript
A smart contract is a program deployed on the blockchain that stores data and runs code when users send transactions. When deployed, it starts with initial state. Users call functions like set() to change stored data or get() to read it. Each call runs the contract code, checks conditions, updates state if allowed, and returns results. The contract keeps its state between calls because it lives on the blockchain. This example shows a simple contract storing a number. Calls to set() update the number, calls to get() return it without changing state. Without input checks, invalid data can be stored, so real contracts add validations. This visual trace helps understand how smart contracts execute step-by-step.