0
0
Blockchain / Solidityprogramming~10 mins

Distributed ledger concept in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a new block to the blockchain list.

Blockchain / Solidity
blockchain.append([1])
Drag options to blanks, or click blank then click option'
A['index', 1, 'data', 'Genesis Block']
B'Genesis Block'
C{'index': 1, 'data': 'Genesis Block'}
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Appending a string or list instead of a dictionary.
Appending just a number.
2fill in blank
medium

Complete the code to calculate the hash of a block's data string.

Blockchain / Solidity
block_hash = hashlib.sha256([1].encode()).hexdigest()
Drag options to blanks, or click blank then click option'
Ablock['timestamp']
Bblock['previous_hash']
Cblock['index']
Dblock['data']
Attempts:
3 left
💡 Hint
Common Mistakes
Hashing the index or timestamp instead of data.
3fill in blank
hard

Fix the error in the code to verify if the blockchain is valid by checking hashes.

Blockchain / Solidity
if blockchain[i]['previous_hash'] != blockchain[[1]]['hash']:
    return False
Drag options to blanks, or click blank then click option'
Ai-1
Blen(blockchain)
C0
Di+1
Attempts:
3 left
💡 Hint
Common Mistakes
Using i+1 which is the next block, not previous.
Using 0 which always points to the first block.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps block indices to their data if the data length is greater than 5.

Blockchain / Solidity
{block['index']: block[1] for block in blockchain if len(block[2]) > 5}
Drag options to blanks, or click blank then click option'
A['data']
B['index']
D['hash']
Attempts:
3 left
💡 Hint
Common Mistakes
Using ['index'] as value instead of ['data'].
Checking length of wrong field.
5fill in blank
hard

Fill all three blanks to create a dictionary of block hashes to their data for blocks with index greater than 0.

Blockchain / Solidity
{block[1]: block[2] for block in blockchain if block[3] > 0}
Drag options to blanks, or click blank then click option'
A['hash']
B['data']
C['index']
D['previous_hash']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys or values.
Filtering on wrong field.