How to save data to a blockchain and how to query it

514 views Asked by At

I am currently working an Online Birth Certificate Registration System using blockchain for my final year project. I have incorporated Moralis in my project to handle the users and linked it to Ganache. I am asking if anyone could tell me how to save information from an html form into the blockchain. I have checked online but no one seems to have the exact answers I'm looking for. Below is the HTML form as well as the Smart contract: When I click on "add details", I want all the information collected to be saved to the blockchain.

  1. I would like to figure out the corresponding JavaScript code
  2. I would like to know the smart contract and Javascript code you can use to query the blockchain so it can display this information so it can be printed out as a Birth Certificate for example.

contract Obdrs {

    uint256 dateOfBirth; //save date as unix timestamp or use a string
    string gender;
    string fullName;
    string placeOfBirth;
    string motherFullname;
    string motherNrc;
    string fatherFullname;
    string fatherNrc;
    string bo; //birthOccurence
    string permanentAddress;
    string contactNumber;
    //... with all of your properties

    function storeBirthCertificate(uint256 _dateOfBirth, string calldata _gender, string calldata _fullName, 
    string calldata _placeOfBirth, string calldata _motherFullname, string calldata _motherNrc, string calldata _fatherFullname,
    string calldata _fatherNrc, string calldata _bo, string calldata _permanentAddress, string calldata _contactNumber) public {

        dateOfBirth = _dateOfBirth;
        gender = _gender;
        fullName = _fullName;
        placeOfBirth = _placeOfBirth;
        motherFullname = _motherFullname;
        motherNrc = _motherNrc;
        fatherFullname = _fatherFullname;
        fatherNrc = _fatherNrc;
        b0 = _bo;
        permanentAddress = _permanentAddress;
        contactNumber = _contactNumber;

    }
}```

1

There are 1 answers

0
ShivaPendem On

this is a simpler problem where you need to check with a series of numbers,

you need to create a mapping, retrieving the data would be more simpler one, but considering a wild card search, then the data would be a complex info where the list of array push need to be considered,

here is my understanding of the storage,

name[]

dateOfBirth[]

fullName[]

gender[]

push the details of all the values in each separate row and the last index position should be mapped to the main usermapping[referenceid]=recordid ( index value of the array)

and this reference id would be shared in the certificate copy, and coming to a wildcard search, that would be a better search algorithm as the data would be large with complete set of records and its type of property like date of birth can be in numbers and name in other format,

consider then in the similar manner to query multiple data,

but keep a not this is not a regular db to query as per your desired style.