Skip to content

A Solidity-based advanced storage contract with Hardhat, enabling efficient data storage, retrieval, and management on the Ethereum blockchain.

License

Notifications You must be signed in to change notification settings

nayandas69/advancedstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdvancedStorage

A Solidity-based smart contract project using Hardhat, designed to store and retrieve numbers and names efficiently. Includes SimpleStorage, ExtraStorage, and StorageFactory contracts.

Features

  • Store and retrieve numbers in the blockchain.
  • Supports multiple storage contracts.
  • Extend functionality with ExtraStorage.
  • Deploy contracts locally using Hardhat.
  • Test contracts with Mocha/Chai.

Prerequisites

  • Windows 11 (or any OS)
  • Node.js (v18+ recommended) ➝ Download
  • NPM (included with Node.js)
  • Hardhat (installed with the project)
  • VS Code (recommended for development)

Installation

Clone the repository

git clone https://github.com/nayandas69/advancedstorage.git
cd advancedstorage

Install dependencies

npm install

How to Use

Start Hardhat Local Blockchain

Open a terminal and run:

npx hardhat node

This will start a local Ethereum blockchain.

Compile Contracts

Run:

npx hardhat compile

If successful, it will output:

Compiled 3 Solidity files successfully (evm target: london).

Deploy Contracts

Open another terminal and run:

npx hardhat run scripts/deploy.js --network localhost

If successful, it will output:

Contract deployed to: 0x123...abc

Run Tests

Run:

npx hardhat test

If successful, it will output:

✅ Should store and retrieve a value (200ms)

Smart Contracts

SimpleStorage

Stores a number and allows retrieval.

function store(uint256 _favoriteNumber) public;
function retrieve() public view returns (uint256);

ExtraStorage

Extends SimpleStorage to always add +5 to stored numbers.

function store(uint256 _favoriteNumber) public override;

StorageFactory

Manages multiple SimpleStorage contracts.

function createSimpleStorageContract() public;
function sfStore(uint256 _index, uint256 _number) public;
function sfGet(uint256 _index) public view returns (uint256);

Troubleshooting

Hardhat: Scripts Disabled on Windows

Error:

npx : File C:\Program Files\nodejs\npx.ps1 cannot be loaded because running scripts is disabled
  • Fix: Run this command:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Hardhat: Trying to use a non-local installation

Error:

Error HH12: Trying to use a non-local installation of Hardhat
  • Fix: Reinstall Hardhat locally:
npm install --save-dev hardhat

Cannot find module '@nomicfoundation/hardhat-toolbox'

Error:

Error: Cannot find module '@nomicfoundation/hardhat-toolbox'
  • Fix: Run:
npm install --save-dev @nomicfoundation/hardhat-toolbox

TypeError: simpleStorage.deployed is not a function

Error:

TypeError: simpleStorage.deployed is not a function
  • Fix:
    Use:
console.log("Contract deployed to:", simpleStorage.address);

Instead of:

await simpleStorage.deployed();

License

This project is licensed under the MIT License.

About

A Solidity-based advanced storage contract with Hardhat, enabling efficient data storage, retrieval, and management on the Ethereum blockchain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published