-1

First, a student applies for a certificate in his/her University . The University creates his degree certificate . Now , how do I write a smart contract in Solidity so that anyone in blockchain can verify based on certain ID related to the certificate. Please explain me how to start this assignment. I only practiced some normal codes on Remix IDE so far. Thank you

1
  • Too broad. Please share your thoughts as well as what you've tried so far. Nov 5, 2019 at 11:11

1 Answer 1

0
  1. When issuing certificate, University sends its details, such as student name, degree, and certificate ID, to the smart contract, and smart contract.
  2. Smart contract checks, that the information originates form the University and, if so, logs the information as an event.
  3. Now, having certificate ID one may query blockchain events and find out whether certificate with this ID was actually issued by the University and, if so, what what was student name and degree.

If you don't want to make student names and degrees public, then University may publish only hash of the certificate, but in this case one would need to be able to calculate hash of the certificate, which may be problematic for paper certificates.

Here is how smart contract code may look like for the second case:

contract CertificateRegistry {
  event Certificate (uint256 indexed id, bytes32 indexed hash);

  address private university;
  uint256 nextID;

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

  function issueCertificate (bytes32 hash) public returns (uint256) {
    require (msg.sender == university);

    emit Certificate (nextID++, hash);
  }

  function calculateHash (string memory name, string memory degree, uint256 issueTime) public view returns (bytes32) {
    return keccak256 (abi.encodePacked (address (this), university, name, degree, issueTime));
  }
}
3
  • So first you are verifying the University using its ID using a smart contract. After that, we take a certificate ID and verify using another smart contract. Nov 5, 2019 at 12:40
  • So after creating a certificate, and when its ID is given to a smart contract for verification , on what basis our smart contract verifies and reports certificate to be genuine or not. Nov 5, 2019 at 12:47
  • The code above works only when certificate is verified by a human or off-chain system. In order to make is usable for other smart contract, the code ought to be modified to store certificate hashes in storage. Nov 5, 2019 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.