Skip to content
Verified contractExactMIT

StudentDatabase

Address0xa27ef94a3e09acbaa10652bd6f7ca71fb7cab11d
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.31

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.31+commit.fd3a2265
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,732,386
Creation transaction
0x8ce79cfe8f…ba5d894325

StuDatabase.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract StudentDatabase {
    // Student structure
    struct Student {
        uint256 studentID;    // Unique Student ID (numeric)
        string name;          // Name of Student
        uint256 age;          // Age
        string class;         // Class (e.g., "10A", "Grade 12")
        bool isMale;          // true = Male, false = Female (shows as tick box in Remix UI)
    }

    // Mapping to store students by StudentID
    mapping(uint256 => Student) private students;

    // Event emitted when a new student is added (visible in Remix console)
    event StudentAdded(uint256 indexed studentID, string name, uint256 age, string class, bool isMale);

    /**
     * @dev Add a new student to the database
     * @param _studentID Unique numeric Student ID
     * @param _name Name of the student
     * @param _age Age of the student
     * @param _class Class of the student
     * @param _isMale true = Male, false = Female (tick box in Remix)
     */
    function addStudent(
        uint256 _studentID,
        string memory _name,
        uint256 _age,
        string memory _class,
        bool _isMale
    ) public {
        // Optional: Prevent overwriting existing student
        require(students[_studentID].studentID == 0, "StudentID already exists");

        students[_studentID] = Student({
            studentID: _studentID,
            name: _name,
            age: _age,
            class: _class,
            isMale: _isMale
        });

        emit StudentAdded(_studentID, _name, _age, _class, _isMale);
    }


    function getStudent(uint256 _studentID)
        public
        view
        returns (
            uint256 studentID,
            string memory name,
            uint256 age,
            string memory class,
            bool isMale
        )
    {
        Student memory s = students[_studentID];
        require(s.studentID != 0, "Student not found");

        return (s.studentID, s.name, s.age, s.class, s.isMale);
    }

    /**
     * @dev Check if a student exists
     * @param _studentID Student ID to check
     */
    function studentExists(uint256 _studentID) public view returns (bool) {
        return students[_studentID].studentID != 0;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.