Skip to content

Latest commit

Β 

History

History
116 lines (75 loc) Β· 2.58 KB

README.md

File metadata and controls

116 lines (75 loc) Β· 2.58 KB

🧠 Simple Storage dApp (Anvil + Viem + MetaMask)

A simple full-stack Ethereum DApp built for local Anvil network using Viem and MetaMask.
It allows users to connect their wallet, set and get a stored value, and fetch user-specific stored values.


βš™οΈ Features

  • 🦊 Connect Wallet β€” Connects to MetaMask wallet
  • ✏️ Update Value β€” Sets a new numeric value in the smart contract
  • πŸ“₯ Get Value β€” Reads the latest global stored value
  • πŸ‘€ User Value β€” Reads the latest value stored by the connected account
  • πŸ”— Local Only β€” Works exclusively with Anvil (Hardhat local chain)

πŸš€ Deployment Instructions

1️⃣ Start Anvil

anvil

This launches a local Ethereum test chain at:

http://localhost:8545
Chain ID: 31337

2️⃣ Deploy the Contract

Use Foundry to deploy:

forge create --rpc-url http://localhost:8545 --private-key <YOUR_PRIVATE_KEY> src/SimpleStorage.sol:SimpleStorage

βœ… Copy the deployed contract address shown in the output β€” you’ll need it for your front-end.


πŸ’» Frontend Setup

3️⃣ Configure Contract Details

In your index.js or index.html script, make sure to update:

const contractAddress = "<YOUR_DEPLOYED_CONTRACT_ADDRESS>";

The code uses Viem’s publicClient and walletClient to interact with the contract.


4️⃣ Run the App

Simply open your index.html file in a browser:

file:///path/to/index.html

or run a local static server (optional):

npx serve .

Then, connect MetaMask (make sure MetaMask is connected to Localhost 8545 / Anvil network) and try:

  1. Connect Wallet β€” to link your MetaMask
  2. Update Value β€” to set a new stored number
  3. Get Value β€” to read the global stored value
  4. User Value β€” to read your account-specific value

πŸ”— Requirements


🧰 Folder Structure

πŸ“¦ simple-storage-dapp
 ┣ πŸ“‚ src
 ┃ β”— πŸ“œ MemoryValue.sol
 ┣ πŸ“œ index.html
 ┣ πŸ“œ index-js.js
 ┣ πŸ“œ README.md

🧠 Notes

  • Works only on Anvil local network (chainId = 31337)
  • You can use pre-funded Anvil private keys for testing
  • If β€œStored value” updates slowly, wait a few seconds for the block to confirm

🧾 License

MIT Β© 2025 β€” Simple Storage Demo