0

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!

1
1

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.

3
  • 1
    I second this and i'd personnally choose the 1st option. However as already said, i'm not sure if storing this on chain is necessary, so unless it's just as a proof of concept, that's usually data that's ok to store on a centralized server
    – Foxxxey
    Aug 12 at 11:11
  • I tried option 1. (a) But the problem I now have is, what if, a subject needs to be added (only to few students)? I mean, if there are 10 students taking 3 subjects and 20 students taking 5 subjects, how many subjects should my struct contain? (b) Using option 1 will imply a fixed format, right? Is there a way to make it dynamic?
    – harshav129
    Aug 17 at 5:56
  • Ok so you can then just make a dynamic subject array and a dynamic subjectmark array in each struct Aug 17 at 5:58
0

That probably isn't a good approach because everything that you store on-chain costs money so storing all of the students marks will probably become pretty expensive. I think you've got the right idea about dividing up your storage between on-chain and traditional databases but I think more could be done to minimize the amount of data required to be stored on-chain.

If I were you, I would either store all of the grades/student pairs in a new CSV file for every transaction and then hash the file and store the significantly smaller hash. Alternatively you could use a database like sqlite and hash the whole database file each time you update publishing the new hash as you go.

In both cases, no grades (or the structure of the file) can be changed without causing a different hash to be generated upon verification. Depending on how many grades and your security needs you can determine a hashing algorithm that works for you. Smaller is better though because every byte on chain will cost you money and make your transaction fee higher.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.