0
0
Blockchain / Solidityprogramming~10 mins

Transaction confirmation handling in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Transaction confirmation handling
Send Transaction
Wait for Mining
Check Confirmation Count
Confirm
This flow shows sending a transaction, waiting for it to be mined, then checking if it has enough confirmations to be considered final.
Execution Sample
Blockchain / Solidity
tx_hash = send_transaction(tx)
confirmations = 0
while confirmations < 3:
    confirmations = get_confirmations(tx_hash)
    sleep(10)
print(f"Transaction confirmed with {confirmations} blocks")
This code sends a transaction and waits until it has at least 3 confirmations before proceeding.
Execution Table
StepActionConfirmationsCondition (confirmations < 3)Next Step
1Send transaction, get tx_hash0TrueWait and check confirmations
2Check confirmations1TrueWait more blocks
3Check confirmations2TrueWait more blocks
4Check confirmations3FalsePrint confirmation message
5Print confirmation message3N/AEnd
💡 Confirmations reached 3, condition is false, loop ends.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
tx_hashNone0xabc1230xabc1230xabc1230xabc1230xabc123
confirmations001233
Key Moments - 3 Insights
Why do we check confirmations in a loop instead of once?
Because the transaction needs multiple blocks to be mined on top to be secure. The loop (see execution_table rows 2-4) waits until confirmations reach the required number.
What happens if confirmations never increase?
The loop keeps waiting (rows 2-4). In real code, you would add a timeout or error handling to avoid waiting forever.
Why do we print confirmation after the loop ends?
Because the loop ends only when confirmations >= 3 (row 4), so printing then means the transaction is safely confirmed.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of confirmations at Step 3?
A0
B2
C1
D3
💡 Hint
Check the 'Confirmations' column at Step 3 in the execution_table.
At which step does the condition 'confirmations < 3' become false?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Condition' column in the execution_table to find when it changes to False.
If we change the required confirmations to 2, at which step would the loop end?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Refer to the 'Confirmations' and 'Condition' columns in the execution_table to see when condition becomes false for 2 confirmations.
Concept Snapshot
Transaction confirmation handling:
- Send transaction and get tx_hash
- Loop: check confirmations count
- Wait until confirmations >= required number
- Confirmations mean blocks mined on top
- Print or proceed after enough confirmations
Full Transcript
This visual execution shows how a blockchain transaction is confirmed. First, the transaction is sent and a transaction hash is received. Then, the program checks how many confirmations the transaction has by counting blocks mined on top. It loops, waiting and checking repeatedly until the confirmations reach the required number (3 in this example). Once confirmed, it prints a message. Variables like tx_hash and confirmations update step-by-step. Key points include why we wait for multiple confirmations for security, and that the loop ends only when confirmations are enough. The quiz questions help check understanding of confirmation counts and loop behavior.