Student Course Registration

Pooja Naik
5 min readOct 14, 2020

What is a Smart Contract?

A smart contract is an agreement between two people in the form of computer code. They run on the blockchain, so they are stored on a public database and cannot be changed. The transactions that happen in a smart contract are processed by the blockchain, which means they can be sent automatically without a third party.

We have written this step-by-step guide to explain what a smart contract is by taking an example of a student registering to an online course by paying some fixed amount. So it mainly includes Educator and Student.

Educator perspective

1.Registering as an Educator and Paying fixed Guarantee of 1 ether
Before placing his course on the platform the educator has to register himself as an educator on the platform and pay an amount of one ether as a guarantee.

We created a Public address variable owner and made deployer address as owner in the constructor. Owner address is made payable as it is able to receive ether from Educator.

We have used address mappings pointing to struct educator. Here educator struct consists of all required details about the educator.

The function EducatorSignUp performs the following:

a). Checks if educator is already Registered. If registered, condition will be false and it reverts back to initial state

b). Checks if msg.value along with function is equal to 1ETH or not. If not, it will revert back to initial state

Output:

If both conditions are true, EducatorSignUp function will get executed and it sets educator details in a mapping called educators with address index.

Transaction of one ether from Educator to the owner as a Guarantee.

Since it is public we can check educator details by pasting educator address.

Details of eduactor

2. Listing course with all required details

We added a struct course with all required variables and made string mapping to struct so that student can register for the course with courseId and made educator address payable because it receives ether from student directly.

Added a bool parameter isActive to check if course is already active with these details.

Added a function AddCourse with following required statements

a)To check whether educator paid guarantee or not

b)To check if course with the same courseId is active already

Output:

If both conditions are passed, it executes addCourse function and add course details into the allCourse[] array and course mapping so that we can list all courses by using array looping or by index.

Student perspective

1.Create an Account

We have created a struct student with required students’ details and mapped it to address.

bool parameter isCreated is helpful in checking if the student has an account already or not while registering for the course.

We have added a function CreateAccount and pushed function arguments(students details) to the studentsmapping.

Output:

Student has successfully created an account.

2. Registering for a Course

We created a struct registrations with course registration detail variables.

We have used address mappings pointing to struct registrations.

Buy using the function RegisterForCourses with courseId as an argument,it checks for the following-

a). If the student is Registered or not,

b). If msg.value is equal to course price or not

Output:

If the above mentioned conditions pass,the amount for the registered course will be transferred to the Educator and a unique registrationId will be allocated for each course being registered.

Transaction of 3 wei from Student to the Educator
Transaction is completed

The final Smart Contract

Output

Here, Smart Contract did all the job of ensuring both educator and student played their roles in the deal. There was no need for middleman, and neither was there any fear that any parties will pull out from the deal, taking money or item with them.

The whole process runs on the Blockchain so every transaction is transparently documented. Blockchain is decentralized, maintained by every ‘node’ that participate in the platform.

--

--