Skip to content

Latest commit

 

History

History
159 lines (132 loc) · 3.29 KB

README.md

File metadata and controls

159 lines (132 loc) · 3.29 KB

📦 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

1️⃣ Clone the repository

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

2️⃣ Install dependencies

npm install

⚙️ How to Use

1️⃣ Start Hardhat Local Blockchain

Open a terminal and run:

npx hardhat node

This will start a local Ethereum blockchain.


2️⃣ Compile Contracts

Run:

npx hardhat compile

If successful, it will output:

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

3️⃣ 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

4️⃣ 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

1. 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

2. 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

3. Cannot find module '@nomicfoundation/hardhat-toolbox'

Error:

Error: Cannot find module '@nomicfoundation/hardhat-toolbox'

Fix: Run:

npm install --save-dev @nomicfoundation/hardhat-toolbox

4. 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.