How to Make Blockchain-Based Notary Service Project

Welcome to all blockchain developers In this article, we add a blockchain project with source code. If you guys are learning blockchain development then you must try this project.


In this blockchain project, we have used the Solidity 8.0 version which will help you to understand the basics of Solidity and also you will get an idea of how Solidity works with this program.



Now let's start to write the code:


blockchain-based notary Service Project

This Ethereum smart contract can be run on Remix so if you guys want to check this program then open Remix and test this contract.


blockchain-based notary Service Code


pragma solidity ^0.8.0; contract NotaryService { struct Document { string data; uint256 timestamp; } mapping(bytes32 => Document) public documents; function notarize(string memory _data) public { bytes32 documentHash = keccak256(abi.encode(_data)); require(documents[documentHash].timestamp == 0, "Document already notarized"); documents[documentHash] = Document(_data, block.timestamp); } function verify(string memory _data) public view returns (bool) { bytes32 documentHash = keccak256(abi.encode(_data)); return documents[documentHash].timestamp != 0; } }


Explanation of blockchain project


  • In this code, data is stored in data variable which is defined in struct.


Now let's talk about the functions :

FunctionDescription
notarizethis function Allows users to notarize a document by providing the document data. The function calculates the hash of data using keccak256 and stores it.
verifyTakes a document data input and verifies if the document has been notarized. It checks if a document with that hash exists.


You guys can run this program in Remix and check the output.


Conclusion


Here in this post, we add blockchain projects with source code so if you want to try your skill then you should read our article and solve the problem.








No comments:

Post a Comment

Popular Posts