0% found this document useful (0 votes)
3 views3 pages

SPDX-License-Identifier: MIT: Pragma

The document outlines the implementation of a decentralized note-making application using Solidity smart contracts. It includes functionalities for creating, reading, updating, and deleting notes, along with events for each operation. The contract maintains a mapping of notes identified by unique IDs and provides a method to retrieve all existing note IDs.

Uploaded by

tulsiraorane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

SPDX-License-Identifier: MIT: Pragma

The document outlines the implementation of a decentralized note-making application using Solidity smart contracts. It includes functionalities for creating, reading, updating, and deleting notes, along with events for each operation. The contract maintains a mapping of notes identified by unique IDs and provides a method to retrieve all existing note IDs.

Uploaded by

tulsiraorane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment No.

9
Class : BE (AIML) Sub : BLCLAB Batch : A2
---------------------------------------------------------------------------------
Aim : Decentralized Note Making App Using CRUD Operation

Code : [Link]
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract NoteStorage {
struct Note {
uint256 id;
string title;
string content;
bool exists;
}

mapping(uint256 => Note) private notes;


uint256 private noteCount;

event NoteCreated(uint256 id, string title);


event NoteUpdated(uint256 id, string title);
event NoteDeleted(uint256 id);

// Create a new note


function createNote(string memory _title, string memory _content) public {
noteCount++;
notes[noteCount] = Note(noteCount, _title, _content, true);
emit NoteCreated(noteCount, _title);
}

// Read a note by ID
function getNote(uint256 _id) public view returns (uint256, string memory,
string memory) {
require(notes[_id].exists, "Note does not exist");
Note memory note = notes[_id];
return ([Link], [Link], [Link]);
}

// Update a note
function updateNote(uint256 _id, string memory _title, string memory
_content) public {
require(notes[_id].exists, "Note does not exist");
notes[_id].title = _title;
notes[_id].content = _content;
emit NoteUpdated(_id, _title);
}

// Delete a note
function deleteNote(uint256 _id) public {
require(notes[_id].exists, "Note does not exist");
delete notes[_id];
emit NoteDeleted(_id);
}

// Get all existing note IDs


function getNoteIds() public view returns (uint256[] memory) {
uint256[] memory ids = new uint256[](noteCount);
uint256 counter = 0;
for (uint256 i = 1; i <= noteCount; i++) {
if (notes[i].exists) {
ids[counter] = i;
counter++;
}
}
// Resize array
uint256[] memory result = new uint256[](counter);
for (uint256 j = 0; j < counter; j++) {
result[j] = ids[j];
}
return result;
}
}
Output :

You might also like