A minimal ERC-20 + vending machine dApp built with Scaffold-ETH 2 (Next.js + Viem + Wagmi + Hardhat). The app lets users buy your ERC-20, transfer it, and sell it back to the Vendor using the standard approve → transferFrom pattern.
This repository is a completed submission for the Token Vendor challenge on speedrunethereum.com.
- App: https://nextjs-llt7ljkl8-dormins-projects.vercel.app/
- Network: Sepolia (chain id 11155111)
- Contracts
Vendor— 0x98219Dc8ECAFDe3B5ed9dAd5DD8bc14963Dd0F87YourToken— 0x35f5CB22E33E7063514a26b3D8680B3Bc86F8176
Paste any address above into a block explorer to view code/txs.
- YourToken.sol — ERC‑20 (OpenZeppelin). Fixed supply, minted in the constructor to deployer.
- Vendor.sol — Vending machine contract:
tokensPerEth = 100buyTokens()payable — swaps ETH → tokenssellTokens(uint256)— requires priorapprove, swaps tokens → ETHwithdraw()— owner‑only, withdraws all ETH- Events:
BuyTokens,SellTokens,Withdraw
- Deploy script transfers
1000 * 10**18tokens to the Vendor and transfers Vendor ownership to the frontend/owner address.
Recommended Node: v20.18.x (Hardhat does not officially support Node 21).
# 1) Install deps (root)
yarn
# 2) Start local chain
cd packages/hardhat
yarn chain
# 3) In a new terminal: deploy locally
cd packages/hardhat
yarn deploy --reset
# 4) In a third terminal: start the dapp
cd packages/nextjs
yarn start
# open http://localhost:3000packages/hardhat/.env
ALCHEMY_API_KEY=
ETHERSCAN_V2_API_KEY=
DEPLOYER_PRIVATE_KEY_ENCRYPTED={...}
FRONTEND_ADDRESS=0xyourOwnerWallet
packages/nextjs/.env.local (optional; defaults are provided)
NEXT_PUBLIC_ALCHEMY_API_KEY=
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
Ensure
.env*files are gitignored. Do not commit private keys or encrypted key blobs.
From packages/hardhat:
yarn verify --network sepolia 0x35f5CB22E33E7063514a26b3D8680B3Bc86F8176 # YourToken (no args)
yarn verify --network sepolia 0x98219Dc8ECAFDe3B5ed9dAd5DD8bc14963Dd0F87 "0x35f5CB22E33E7063514a26b3D8680B3Bc86F8176" # Vendor(tokenAddress)- Connect wallet (burner or MetaMask) on Sepolia.
- Buy: enter tokens to buy → wallet pays
amount / tokensPerEthETH. - Transfer: send tokens to any address via
transfer. - Sell:
approve(Vendor, amount)thensellTokens(amount)to receive ETH back.
- Solidity, Hardhat, hardhat‑deploy
- OpenZeppelin ERC20, Ownable
- Next.js (app router), Viem, Wagmi, RainbowKit
- Tailwind + daisyUI
tokensPerEthhard‑coded to 100.- Vendor preloaded with 1000 YTK in the deploy script.
- Vendor ownership transferred to
FRONTEND_ADDRESSfrom.env. - Frontend route:
/token-vendorincludes Buy / Transfer / Approve+Sell UX and shows balances.
- Addresses are public by design. Never commit private keys, mnemonics or the encrypted key JSON.
- Keep owner funds in a non‑burner wallet.
# Deploy to Sepolia
cd packages/hardhat
yarn deploy --network sepolia --reset
# Verify on Sepolia (see Verify above)
# Build frontend
cd packages/nextjs
yarn build
# Deploy frontend to Vercel (once linked)
vercel --prodMIT