Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlockNotes - Solidity Smart Contract

Overview

This repository contains a smart contract written in Solidity that functions as a simple digital notebook. The contract allows users to create, store, and share short notes. Users can manage the visibility of their notes by keeping them private, sharing them with specific users, or making them public for everyone to read.

The project also includes a test suite ensuring a minimum of 90% test coverage and optimizations for gas efficiency and security.

Contract Details

  • Contract Name: BlockNotesk
  • Version: Solidity ^0.8.26
  • Network: Ethereum Sepolia Testnet
  • Deployed Address: Link to Etherscan (Replace with actual link to verified contract)

Prerequisites

Before running or deploying the contract, make sure you have:

  • Node.js and npm installed
  • Truffle or Hardhat framework
  • Solidity ^0.8.26
  • Ganache for local testing or any Ethereum-compatible network.

Contract Structure

Visibility Enum

  • Private:
    Only the owner can read the note.

  • Shared:
    The owner can share the note with specific users.

  • Public:
    Anyone can read the note.

Mappings & Arrays

  • Mapping:
    Notes are stored in a mapping of noteId to Note struct.

  • User's Notes:
    Each user has a list of their note IDs stored in a mapping of address to uint256[].

Functions

  • createNote(string memory content, Visibility visibility):
    Creates a new note with specified visibility.

  • getNote(uint256 _noteId):
    Reads a note, respecting the visibility settings.

  • shareWith(uint256 noteId, address user):
    Shares a note with a specific address.

  • deleteNote(uint256 noteId):
    Deletes a note owned by the user.

  • changeVisibility(uint256 noteId, Visibility newVisibility):
    Allows the owner to change the visibility of a note.

  • receive():
    Returns ether to users whom mistakenly sends funds to contract.

Events

  • NoteCreated(uint256 noteId, address owner)

  • NoteShared(uint256 noteId, address sharedWith)

  • NoteVisibilityChanged(uint256 noteId, Visibility newVisibility)

  • NoteDeleted(uint256 noteId)

Gas Optimizations

  • Custom Errors:
    Reduces gas costs by replacing string-based require messages with custom errors.

  • Efficient Storage Access:
    Reduces gas by minimizing redundant storage reads in modifiers.

  • Mappings Instead of Arrays:
    Optimizes user access control with O(1) lookups rather than more expensive dynamic array operations.

Fallback & Receive Functions

The contract includes a receive() function to handle any ETH sent to the contract. However, ETH handling is not a primary function of this contract.

Installation

Clone the repository:

git https://github.com/nativealien/solidity-assignment.git
cd solidity-assignment

Install dependencies:

npm install

Compile the contract:

npx hardhat compile

Run the tests:

npm test

Testing

Run the test suite to ensure the contract works as expected:

npx hardhat test

Ensure that test coverage is above 90% by running:

npx hardhat coverage

alt text

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages