0
0
Blockchain / Solidityprogramming~20 mins

Distributed ledger concept in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Distributed Ledger Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this simple blockchain ledger update?

Consider a blockchain ledger represented as a list of blocks. Each block contains a transaction amount. What will be the total balance after adding these blocks?

Blockchain / Solidity
ledger = [100, -20, 50]
total_balance = sum(ledger)
print(total_balance)
A130
B150
C180
D100
Attempts:
2 left
💡 Hint

Sum all the amounts in the ledger list.

🧠 Conceptual
intermediate
1:00remaining
Which property ensures all participants have the same copy of the ledger?

In a distributed ledger system, what is the key property that guarantees all nodes share the same data?

ASmart contracts
BEncryption
CMining
DConsensus
Attempts:
2 left
💡 Hint

Think about how nodes agree on the ledger state.

🔧 Debug
advanced
2:00remaining
What error does this blockchain block validation code raise?

Analyze the code below that validates a block's hash. What error will it raise when run?

Blockchain / Solidity
def validate_block(block):
    if block['hash'] == block['prev_hash']:
        return True
    else:
        return False

block = {'hash': 'abc123', 'prev_hash': 'def456'}
print(validate_block(block))
AKeyError because 'hash' key is missing
BSyntaxError due to missing colon after else
CTypeError because block is not a dict
DReturns True
Attempts:
2 left
💡 Hint

Check the syntax of the if-else statement.

📝 Syntax
advanced
1:30remaining
Which option correctly creates a new block dictionary with a timestamp?

Choose the code snippet that correctly creates a block dictionary with keys 'index', 'timestamp', and 'data'.

Ablock = {'index': 1, 'timestamp': '2024-06-01', 'data': 'Transaction'}
Bblock = {'index': 1, 'timestamp' = '2024-06-01', 'data': 'Transaction'}
Cblock = {'index': 1; 'timestamp': '2024-06-01'; 'data': 'Transaction'}
Dblock = {'index': 1, 'timestamp': '2024-06-01' 'data': 'Transaction'}
Attempts:
2 left
💡 Hint

Remember the syntax for dictionary key-value pairs in Python.

🚀 Application
expert
2:00remaining
What is the length of the blockchain after adding these blocks?

Given the initial blockchain and a function to add blocks, what is the length of the blockchain after adding two new blocks?

Blockchain / Solidity
blockchain = [{'index': 0, 'data': 'Genesis'}]

def add_block(chain, data):
    index = chain[-1]['index'] + 1
    chain.append({'index': index, 'data': data})

add_block(blockchain, 'Tx1')
add_block(blockchain, 'Tx2')
print(len(blockchain))
A4
B2
C3
D1
Attempts:
2 left
💡 Hint

Count the original block plus the added blocks.