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.
- π¦ 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)
anvilThis launches a local Ethereum test chain at:
http://localhost:8545
Chain ID: 31337
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.
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.
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:
- Connect Wallet β to link your MetaMask
- Update Value β to set a new stored number
- Get Value β to read the global stored value
- User Value β to read your account-specific value
π¦ simple-storage-dapp
β£ π src
β β π MemoryValue.sol
β£ π index.html
β£ π index-js.js
β£ π README.md
- 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
MIT Β© 2025 β Simple Storage Demo