Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Transaction confirmation handling
📖 Scenario: You are building a simple blockchain wallet app. When you send a transaction, you want to check how many confirmations it has received on the blockchain to know if it is secure.
🎯 Goal: Create a program that stores a transaction with its current confirmation count, sets a confirmation threshold, checks if the transaction is confirmed enough, and then prints a message about the confirmation status.
📋 What You'll Learn
Create a dictionary called transaction with keys 'id' and 'confirmations' and exact values 'tx123' and 2
Create a variable called confirmation_threshold and set it to 3
Create a boolean variable called is_confirmed that is True if transaction['confirmations'] is greater than or equal to confirmation_threshold, otherwise False
Print Transaction tx123 confirmed if is_confirmed is True, otherwise print Transaction tx123 pending
💡 Why This Matters
🌍 Real World
Blockchain wallets and explorers show transaction confirmation status to users so they know when their transactions are secure.
💼 Career
Understanding how to handle transaction confirmations is important for blockchain developers building wallets, exchanges, or monitoring tools.
Progress0 / 4 steps
1
Create the transaction data
Create a dictionary called transaction with keys 'id' and 'confirmations' and values 'tx123' and 2 respectively.
Blockchain / Solidity
Hint
Use curly braces to create a dictionary with the exact keys and values.
2
Set the confirmation threshold
Create a variable called confirmation_threshold and set it to 3.
Blockchain / Solidity
Hint
Just assign the number 3 to the variable confirmation_threshold.
3
Check if transaction is confirmed
Create a boolean variable called is_confirmed that is True if transaction['confirmations'] is greater than or equal to confirmation_threshold, otherwise False.
Blockchain / Solidity
Hint
Use the >= operator to compare confirmations with the threshold.
4
Print confirmation status
Print Transaction tx123 confirmed if is_confirmed is True, otherwise print Transaction tx123 pending.
Blockchain / Solidity
Hint
Use an if-else statement and f-strings to print the correct message.
Practice
(1/5)
1. What does transaction confirmation mean in blockchain?
easy
A. It means the transaction is deleted from the blockchain.
B. It means the transaction is reversed by the user.
C. It means the transaction is pending and not yet sent.
D. It means the transaction is safely recorded on the blockchain.
Solution
Step 1: Understand transaction confirmation meaning
Transaction confirmation means the blockchain network has recorded the transaction securely.
Step 2: Compare options with definition
Only It means the transaction is safely recorded on the blockchain. correctly states that confirmation means safe recording on the blockchain.
Final Answer:
It means the transaction is safely recorded on the blockchain. -> Option D
Quick Check:
Transaction confirmation = safe recording [OK]
Hint: Confirmation means transaction is securely recorded [OK]
Common Mistakes:
Confusing confirmation with transaction pending state
Thinking confirmation means deletion or reversal
Assuming confirmation means user approval
2. Which of the following is the correct way to wait for a transaction confirmation in JavaScript using async/await?
easy
A. await transaction.confirm();
B. transaction.wait();
C. await transaction.wait();
D. transaction.confirm();
Solution
Step 1: Identify correct async syntax
To wait for a promise in JavaScript, use await before the async function call.
Step 2: Match function name for confirmation
The standard method to wait for transaction confirmation is wait(), not confirm().
Final Answer:
await transaction.wait(); -> Option C
Quick Check:
Use await with wait() to confirm transaction [OK]
Hint: Use await with wait() method to confirm transaction [OK]
Common Mistakes:
Forgetting to use await causing unresolved promises
Using wrong method name like confirm()
Calling wait() without await leading to no pause
3. What will be the output of this JavaScript code snippet?