Ethereum Blockchain – Storing and Retrieving Data Efficiently

storage

I am trying to build a simple application using Ethereum Smart Contracts that requires storing marks of students. How should I store and retrieve them?

Say there are students and few subjects that each student takes. My idea is to store marks of a student in a particular subject as a transaction and such transactions will be mined into a block. I will then note down the block number to which this transaction was mined against the student in a separate database. This database will be storing student name/id, subject and block number where I can find the student's marks.

Is this a good approach? Also, is it possible to retrieve data (marks) from multiple blocks to display a consolidated marksheet?

How will I need to modify the smart contract if I would also like to store students' feedback regarding the tests?

If you can direct me to a smart contract example/tutorial explaining the storage and data retrival part, I will be grateful. Many Thanks in advance!

Best Answer

There are more than 1 way of doing this for example:

Option 1:

You can create a Smart Contract that has an array of students.

Each student will be of type Struct containing their necessary info and marks per subject for instance.

ex.

struct Student{
string Name;
string Surname;
uint Grade;
uint Subject1Mark;
uint Subject2Mark;
...
uint FinalMark;
etc.
}

you can easily then read back the students info by introduce a mapping per strudent.

For student's test feedback per test you can make another struct called tests and store feedback per student in them.

another option:

Option 2:

You can create a Smart Contract that has an array of Subjects.

Each subject will be of type Struct containing the students and their marks per that subject;

ex.

struct Subject1{
string[] Students;
uint[] Grades;
...
etc.
}

now in terms of subjects you can call users and their marks via a mapping.

There are various ways to solve this problem by using a combination of structs and mappings. I hope this could give you some guidance!

Just Note: Storing info on the blockchain could become very costly, so try only storing the necessary info if you want it all on chain.

Related Topic