0

I'm currently working on a project where I have to store Student's basic data using Blockchain. I managed to to do so, but now I want the data to get Stored on the IPFS instead of the Blockchain, and the generated hash value to get stored on the Blockchain, for which I'm using Ganache. As I'm new to this field and also, don't have much knowledge of JavaScript as well, I don't have much information how to go ahead. Below is code which I wrote in Solidity:

pragma solidity ^0.8.17;

contract StudentData 
{
    struct StudentInfo
    {
        uint roll;
        string name;
        uint cgpa;
        bool placed;
    }

    address public admin;

    constructor() public
    {
        admin = msg.sender;
    }

    mapping(address => StudentInfo) studentdata;

    mapping(address => bool) studentaddress;

    mapping(address => bool) guestaddress;

    function RegAsStudent(address _addr) public 
    {
        require(_addr != admin, "Admin can't Register As Student. ");
        studentaddress[_addr] = true;
    }

    function RegAsGuest(address _addr) public payable {
        require(studentaddress[_addr] != true, "Students are not allowed to Register as Guest Viewers. ");
        require(msg.value == 1 ether, "Please Transfer Exact Amount to get Access.");
        guestaddress[_addr] = true;
    }

    function InputData
    (address _key, 
    uint _roll, 
    string memory _name, 
    uint _cgpa, 
    bool _placed) public 
    {
        require(_key != admin, "Change Account to feed Student's Data.");
        require(studentaddress[_key] == true, "You are not a Student! ");
        StudentInfo memory data = StudentInfo(_roll, _name, _cgpa, _placed);
        studentdata[_key] = data;
    }

    function DisplayData(address _key) public view returns (StudentInfo memory) {
        require(msg.sender == admin || studentaddress[msg.sender] == true,
        "Only Admin & Students can access the Data. ");
        return studentdata[_key];
    }

    function ViewAsGuest(address _key) public view returns (StudentInfo memory) {
        require(guestaddress[msg.sender] == true, "Only Paid Guests can Access.");
        return studentdata[_key];
    }
}

And Below is the JavaScript Code which I wrote under the Migrations Folder of Truffle to Deploy the Smart Contract:

const StudentData = artifacts.require("StudentData.sol");

module.exports = async function(deployer) {
  await deployer.deploy(StudentData);
};

I tried Installing the ipfs-http-client and js-ipfs modules using the npm, but I'm not aware of how to incorporate them in my Project and also what kind of changes I have to do in my code, how do I have to change my Migrations folder and Truffle-config files so that my aim gets fulfilled. I'd be extremely grateful if someone can help me out.

0 Answers0