A complete Web3 authentication system with wallet connection, signature verification, and token balance display.
- Connect to MetaMask wallet
- Sign messages to verify wallet ownership
- JWT-based authentication
- Protected routes
- Display ETH, USDT, and USDC balances
- React.js
- React Router for navigation
- Tailwind CSS for styling
- ethers.js for Ethereum interaction
- Axios for API requests
- Go (Golang)
- Gin web framework
- JWT for authentication
- PostgreSQL database
web3auth/
│
├── frontend/
│ ├── public/
│ │ ├── index.html
│ │ └── favicon.ico
│ │
│ ├── src/
│ │ ├── components/
│ │ │ ├── ConnectWallet.jsx
│ │ │ └── Dashboard.jsx
│ │ │
│ │ ├── utils/
│ │ │ └── web3.js
│ │ │
│ │ ├── App.jsx
│ │ ├── index.jsx
│ │ └── index.css
│ │
│ ├── package.json
│ └── tailwind.config.js
│
├── backend/
│ ├── cmd/
│ │ └── server/
│ │ └── main.go
│ │
│ ├── internal/
│ │ ├── auth/
│ │ │ ├── handler.go
│ │ │ ├── middleware.go
│ │ │ ├── service.go
│ │ │ └── jwt.go
│ │ │
│ │ ├── user/
│ │ │ ├── handler.go
│ │ │ ├── model.go
│ │ │ └── repository.go
│ │ │
│ │ └── utils/
│ │ ├── db.go
│ │ ├── ethereum.go
│ │ └── middleware.go
│ │
│ ├── migrations/
│ │ └── 001_create_users.sql
│ │
│ ├── go.mod
│ └── go.sum
│
├── docker-compose.yml
└── README.md
- Node.js and npm
- Go (1.16+)
- Docker and Docker Compose
- PostgreSQL (or use the Docker container)
- Clone the repository
git clone https://github.com/biganashvili/web3auth.git
cd web3auth
- Start the services with Docker Compose
docker-compose up -d
- Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8080/api
cd frontend
npm install
npm start
cd backend
go mod download
go run cmd/server/main.go
- User clicks "Connect MetaMask" button
- Frontend requests wallet connection via MetaMask
- Backend generates a random nonce for the address
- User signs a message containing this nonce
- Backend verifies the signature cryptographically
- If valid, a JWT token is issued and stored in localStorage
- User is redirected to the dashboard where they can see their token balances
MIT
Sergi Biganashvili