The StudentPortal is a Solidity smart contract designed to manage student records on the Ethereum blockchain. It provides functionality for registering, updating, and deleting student information, as well as retrieving individual and collective student data.
- Register new students with detailed information
- Update existing student records
- Delete student records
- Retrieve individual student details
- Get the total count of registered students
- Fetch all registered students' information
- Ownership control for administrative functions
- Solidity Version: ^0.8.24
- License: MIT
The contract uses a Student
struct to store the following information for each student:
- Name
- Date of Birth
- Local Government Area
- Country
- State
Allows the contract owner to register a new student.
function registerStudent(
string memory _name,
string memory _email,
uint256 _dateOfBirth,
string memory _localGovernmentArea,
string memory _country,
string memory _state
) external onlyOwner
Enables the contract owner to update an existing student's information.
function updateStudent(
uint256 _studentId,
string memory _name,
string memory _email,
uint256 _dateOfBirth,
string memory _localGovernmentArea,
string memory _country,
string memory _state
) external onlyOwner
Allows the contract owner to delete a student record.
function deleteStudent(uint256 _studentId) external onlyOwner
Retrieves the information of a specific student.
function getStudent(uint256 _studentId) external view returns (Student memory)
Returns the total number of registered students.
function getStudentCount() external view returns (uint256)
Fetches information of all registered students.
function getAllStudents() external view returns (Student[] memory)
The contract emits the following events:
StudentRegistered(uint256 indexed studentId)
StudentUpdated(uint256 indexed studentId)
StudentDeleted(uint256 indexed studentId)
The contract implements an onlyOwner
modifier to restrict access to administrative functions (register, update, delete) to the contract owner only.
To deploy the StudentPortal contract:
-
Ensure you have a development environment set up with Hardhat and Ethers.js.
-
Create a deployment script (e.g.,
deploy-student-portal.js
) in yourscripts
folder. -
Run the deployment script using Hardhat:
npx hardhat run scripts/deploy-student-portal.js --network lisk-sepolia
-
Save the deployed contract address for future interactions.
- Only the contract owner can perform administrative actions.
- The contract stores data on-chain, which may not be suitable for sensitive information in a production environment.
- Consider implementing additional access controls or encryption for sensitive data.
- Thoroughly test the contract before deploying to a live network.
- Implement pagination for
getAllStudents
to handle large numbers of records efficiently. - Add events for important state changes.
- Consider implementing a multi-sig wallet for owner actions.
- Explore off-chain storage solutions for scalability and privacy.
This project is licensed under the MIT License. See the LICENSE file for details.