0
0
Blockchain / Solidityprogramming~30 mins

Structs in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Structs in Blockchain
📖 Scenario: You are building a simple blockchain application that stores information about digital assets. Each asset has a name, an owner, and a value. You will use structs to organize this data clearly.
🎯 Goal: Create a struct to represent a digital asset, store multiple assets, and display their details.
📋 What You'll Learn
Create a struct called Asset with fields name (string), owner (string), and value (uint).
Create a list called assets to hold multiple Asset structs.
Add a configuration variable minValue to filter assets by their value.
Use a loop to select assets with value greater than or equal to minValue.
Print the details of the selected assets.
💡 Why This Matters
🌍 Real World
Structs help organize complex data in blockchain apps, like digital assets, transactions, or user profiles.
💼 Career
Understanding structs is key for blockchain developers to build clear, maintainable smart contracts and decentralized apps.
Progress0 / 4 steps
1
Define the Asset struct and create assets list
Define a struct called Asset with fields name (string), owner (string), and value (uint). Then create a list called assets with these exact entries: {"name": "ArtPiece", "owner": "Alice", "value": 100}, {"name": "CryptoKitty", "owner": "Bob", "value": 50}, and {"name": "RareCoin", "owner": "Charlie", "value": 200}.
Blockchain / Solidity
Need a hint?

Use struct keyword to define Asset. Create an array of Asset with the given entries.

2
Add a minimum value filter
Create a variable called minValue of type uint and set it to 100.
Blockchain / Solidity
Need a hint?

Use uint minValue = 100; to set the minimum value filter.

3
Select assets with value >= minValue
Create a new list called selectedAssets of type Asset[]. Use a for loop with variable i to go through assets. Inside the loop, use an if statement to check if assets[i].value is greater than or equal to minValue. If yes, add assets[i] to selectedAssets.
Blockchain / Solidity
Need a hint?

Use a for loop and if condition to filter assets. Use push to add to selectedAssets.

4
Print selected assets details
Use a for loop with variable j to go through selectedAssets. Inside the loop, print the asset's name, owner, and value in this exact format: Asset: [name], Owner: [owner], Value: [value].
Blockchain / Solidity
Need a hint?

Use a for loop and string concatenation to prepare each selected asset's details for output. Solidity does not support console.log; instead, return the strings or emit events.