Compare commits
12
Commits
7ce1f05f52
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f94e5c8dc9 | ||
|
|
f9f92107c2 | ||
|
|
b540e1372e | ||
|
|
f410f09d67 | ||
|
|
9e3e303dc0 | ||
|
|
5a14b8efce | ||
|
|
81d5a5dabd | ||
|
|
fc3a4333db | ||
|
|
5db30add74 | ||
|
|
c4a50e8b3b | ||
|
|
cf3d999a2e | ||
|
|
8176bf500f |
@@ -1,5 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.env
|
.env
|
||||||
|
*.sol
|
||||||
/node_modules/
|
/node_modules/
|
||||||
|
|
||||||
# React Router
|
# React Router
|
||||||
|
|||||||
@@ -1,87 +1,72 @@
|
|||||||
# Welcome to React Router!
|
# Welcome to CLEARNET!
|
||||||
|
|
||||||
A modern, production-ready template for building full-stack React applications using React Router.
|
A new Decentralized VPN
|
||||||
|
|
||||||
[](https://stackblitz.com/github/remix-run/react-router-templates/tree/main/default)
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- 🚀 Server-side rendering
|
|
||||||
- ⚡️ Hot Module Replacement (HMR)
|
|
||||||
- 📦 Asset bundling and optimization
|
|
||||||
- 🔄 Data loading and mutations
|
|
||||||
- 🔒 TypeScript by default
|
|
||||||
- 🎉 TailwindCSS for styling
|
|
||||||
- 📖 [React Router docs](https://reactrouter.com/)
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
Before you use ClearNet make sure you have wireguard installed on your computer.
|
||||||
|
|
||||||
### Installation
|
The download link for wireguard is provided below.
|
||||||
|
|
||||||
Install the dependencies:
|
[Download Wireguard](https://www.wireguard.com/install)
|
||||||
|
|
||||||
|
You can start using clearnet by clicking on the link below.
|
||||||
|
|
||||||
|
[CLEARNET WebClient](http://depin.msbd.cloud)
|
||||||
|
|
||||||
|
## Use the web app
|
||||||
|
|
||||||
|
1. When you open the website link above you will be greeted with blank page with no available servers.
|
||||||
|
|
||||||
|
2. To connect to your metamask wallet, just click login. Then choose your wallet and connect.
|
||||||
|
|
||||||
|
3. Make sure you are using the sepolia test net as the contract is deployed there.
|
||||||
|
|
||||||
|
4. When you see the metamask logo on the top right it means you are connected.
|
||||||
|
|
||||||
|
5. You need some CLR tokens to register to the network. For testing purposes, we prepared a faucet where you can get some tokens. Go to the Faucet page and click "Claim CLR" to get some Tokens. We suggest you claim it twice to make sure you have enough tokens.
|
||||||
|
|
||||||
|
6. After you have some tokens, click the metamask icon on the top right to register to the network.
|
||||||
|
|
||||||
|
7. It will ask for your confirmation twice, be patient and wait for the process to complete.
|
||||||
|
|
||||||
|
8. When you return to the home page you will see the list of available nodes to connect to.
|
||||||
|
|
||||||
|
9. Pick a node and click connect. You will be promted to download the wireguard config file.
|
||||||
|
|
||||||
|
10. Import the config fire to your wireguard client. you can start using the VPN now.
|
||||||
|
|
||||||
|
11. When you finish click disconnect on the node. You will be prompted to enter a rating for the server. You can choose to rate or not rate. Make sure to click confirm on metamask. (if you choose to rate it will ask for your confirmation twice. The first one is to sign your rating)
|
||||||
|
|
||||||
|
## Local Setup
|
||||||
|
If you prefer a local setup or the web site above is down, you can follow the instructions below.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
Make sure you have nodejs installed on your system
|
||||||
|
|
||||||
|
If not, you can downlaod from their offical website:
|
||||||
|
|
||||||
|
[https://nodejs.org/en/download](https://nodejs.org/en/download)
|
||||||
|
|
||||||
|
After you have node installed
|
||||||
|
|
||||||
|
Clone this repository and cd into it
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd MSBD5017-Depin-WebClient
|
||||||
|
```
|
||||||
|
run
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
to install all the dependencies
|
||||||
|
|
||||||
### Development
|
next, run
|
||||||
|
|
||||||
Start the development server with HMR:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
Your application will be available at `http://localhost:5173`.
|
|
||||||
|
|
||||||
## Building for Production
|
|
||||||
|
|
||||||
Create a production build:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
A build folder will appear, you can use your web server of choice to serve this foler or just use the built in web server and run
|
||||||
## Deployment
|
|
||||||
|
|
||||||
### Docker Deployment
|
|
||||||
|
|
||||||
To build and run using Docker:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t my-app .
|
npm start
|
||||||
|
|
||||||
# Run the container
|
|
||||||
docker run -p 3000:3000 my-app
|
|
||||||
```
|
```
|
||||||
|
The server will be listening on port 3000.
|
||||||
|
|
||||||
The containerized application can be deployed to any platform that supports Docker, including:
|
|
||||||
|
|
||||||
- AWS ECS
|
|
||||||
- Google Cloud Run
|
|
||||||
- Azure Container Apps
|
|
||||||
- Digital Ocean App Platform
|
|
||||||
- Fly.io
|
|
||||||
- Railway
|
|
||||||
|
|
||||||
### DIY Deployment
|
|
||||||
|
|
||||||
If you're familiar with deploying Node applications, the built-in app server is production-ready.
|
|
||||||
|
|
||||||
Make sure to deploy the output of `npm run build`
|
|
||||||
|
|
||||||
```
|
|
||||||
├── package.json
|
|
||||||
├── package-lock.json (or pnpm-lock.yaml, or bun.lockb)
|
|
||||||
├── build/
|
|
||||||
│ ├── client/ # Static assets
|
|
||||||
│ └── server/ # Server-side code
|
|
||||||
```
|
|
||||||
|
|
||||||
## Styling
|
|
||||||
|
|
||||||
This template comes with [Tailwind CSS](https://tailwindcss.com/) already configured for a simple default starting experience. You can use whatever CSS framework you prefer.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Built with ❤️ using React Router.
|
|
||||||
|
|||||||
@@ -1,8 +1,22 @@
|
|||||||
import { Box, Card, CardContent, Typography, Link, Button, Avatar, Stack } from "@mui/material";
|
import { Box, Card, CardContent, Typography, Link, Button, Avatar, Stack } from "@mui/material";
|
||||||
import GitHubIcon from "@mui/icons-material/GitHub";
|
import GitHubIcon from "@mui/icons-material/GitHub";
|
||||||
|
import GetAppIcon from "@mui/icons-material/GetApp";
|
||||||
|
|
||||||
|
const WIREGUARD_COLOR = "#88171A";
|
||||||
|
|
||||||
|
function WireGuardLogo({ size = 40 }: { size?: number }) {
|
||||||
|
return (
|
||||||
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
|
||||||
|
<circle cx="12" cy="12" r="12" fill={WIREGUARD_COLOR} />
|
||||||
|
<path d="M6 12c0-3.314 2.686-6 6-6s6 2.686 6 6-2.686 6-6 6S6 15.314 6 12z" fill="#fff" opacity="0.15" />
|
||||||
|
<path d="M8.5 11.5c1-2 3-3 5-3s4 1 5 3" stroke="#fff" strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function About() {
|
export default function About() {
|
||||||
const repo = "https://github.com/cochrane2063/MSBD5017-Depin-WebClient";
|
const repo = "https://github.com/cochrane2063/MSBD5017-Depin-WebClient";
|
||||||
|
const wireguard = "https://www.wireguard.com/install/";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", justifyContent: "center", p: 3 }}>
|
<Box sx={{ display: "flex", justifyContent: "center", p: 3 }}>
|
||||||
@@ -32,7 +46,59 @@ export default function About() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
sx={{
|
||||||
|
width: 420,
|
||||||
|
maxWidth: "100%",
|
||||||
|
borderLeft: `6px solid ${WIREGUARD_COLOR}`,
|
||||||
|
background: "linear-gradient(180deg, rgba(122,193,67,0.04), transparent 60%)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CardContent>
|
||||||
|
<Stack direction="row" spacing={2} alignItems="center" sx={{ mb: 1 }}>
|
||||||
|
<Avatar sx={{ bgcolor: "transparent" }}>
|
||||||
|
<WireGuardLogo />
|
||||||
|
</Avatar>
|
||||||
|
<Typography variant="h5" sx={{ color: WIREGUARD_COLOR, fontWeight: 700 }}>
|
||||||
|
Download Wireguard Client
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Typography variant="body1" color="text.secondary" paragraph>
|
||||||
|
Wireguard client for the MSBD5017 Depin project.
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography variant="body2" color="text.secondary" paragraph>
|
||||||
|
This project uses the Wireguard VPN protocol. You can download the Wireguard client from the official website.
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Stack direction="row" spacing={2} alignItems="center">
|
||||||
|
<Link href={wireguard} target="_blank" rel="noopener noreferrer" underline="none">
|
||||||
|
<Button
|
||||||
|
startIcon={<GetAppIcon />}
|
||||||
|
variant="contained"
|
||||||
|
sx={{
|
||||||
|
bgcolor: WIREGUARD_COLOR,
|
||||||
|
"&:hover": { bgcolor: "#65a836" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Download WireGuard
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
href="https://www.wireguard.com/quickstart/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
sx={{ borderColor: WIREGUARD_COLOR, color: WIREGUARD_COLOR }}
|
||||||
|
>
|
||||||
|
Quickstart Guide
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// ...existing code...
|
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "constructor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "spender",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "allowance",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "needed",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InsufficientAllowance",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "sender",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "balance",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "needed",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InsufficientBalance",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "approver",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InvalidApprover",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "receiver",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InvalidReceiver",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "sender",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InvalidSender",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "spender",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "ERC20InvalidSpender",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "owner",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "OwnableInvalidOwner",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "account",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "OwnableUnauthorizedAccount",
|
||||||
|
"type": "error"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "owner",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "spender",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "value",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "Approval",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "previousOwner",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "newOwner",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "OwnershipTransferred",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "from",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "to",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "value",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "Transfer",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "owner",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "spender",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "allowance",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "spender",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "value",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "approve",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "account",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "balanceOf",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_amount",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "burn",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "decimals",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint8",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "_to",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_amount",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "mint",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "name",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "owner",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "renounceOwnership",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "symbol",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "totalSupply",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "to",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "value",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transfer",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "from",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "to",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "value",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferFrom",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "newOwner",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferOwnership",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
}
|
||||||
|
]
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,141 @@
|
|||||||
|
import { Web3, type Bytes } from 'web3';
|
||||||
|
import type { Node, NodeInfo, PaymentChannelInfo } from '../Util';
|
||||||
|
import clearNetJson from './ClearNet/ClearNet.json';
|
||||||
|
import clrTokenJson from './CLRToken/CLRToken.json';
|
||||||
|
|
||||||
|
const clearNetABI = (clearNetJson as any).abi ?? clearNetJson;
|
||||||
|
const clrTokenABI = (clrTokenJson as any).abi ?? clrTokenJson;
|
||||||
|
const clearNetAddress = "0x0305e95225f65db13e98c775dbb95b98178ae73b";
|
||||||
|
const clrTokenAddress = "0xf1664c17887767c8f58695846babb349ca61d2e9";
|
||||||
|
// const clearNetAddress = "0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae";
|
||||||
|
// const clrTokenAddress = "0x5fc8d32690cc91d4c39d9d3abcbd16989f875707";
|
||||||
|
|
||||||
|
const DEFAULT_MIN_STAKE = BigInt(100) * BigInt(1e18); // 100 CLR
|
||||||
|
|
||||||
|
|
||||||
|
export const getActiveNodes = async (provider: any): Promise<Node[]> => {
|
||||||
|
if (!provider) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const activeNodes: string[] = await clearnet_contract.methods.getActiveNodes().call();
|
||||||
|
const nodes: Node[] = await Promise.all(activeNodes.map(async (node: string) => {
|
||||||
|
const nodeInfo: NodeInfo = await clearnet_contract.methods.getNodeInfo(node).call();
|
||||||
|
return {
|
||||||
|
address: node,
|
||||||
|
ip: nodeInfo.ipAddress,
|
||||||
|
port: Number(nodeInfo.port),
|
||||||
|
traffic: 0,
|
||||||
|
price: Number(nodeInfo.pricePerMinute) / 1e18,
|
||||||
|
pricePerMinute: nodeInfo.pricePerMinute,
|
||||||
|
rating: Number(nodeInfo.reputationScore) / 1000,
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
console.log("Fetched nodes:", nodes);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function approveCLRTokenSpending(provider: any,account: string) {
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clr_token_contract = new web3.eth.Contract(clrTokenABI, clrTokenAddress);
|
||||||
|
const gasPrice = await web3.eth.getGasPrice();
|
||||||
|
const gasLimit = 300000;
|
||||||
|
const tx = await clr_token_contract.methods.approve(clearNetAddress, DEFAULT_MIN_STAKE).send({
|
||||||
|
from: account,
|
||||||
|
gas: String(gasLimit),
|
||||||
|
gasPrice: String(gasPrice),
|
||||||
|
});
|
||||||
|
console.log(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function openPaymentChannel(provider: any,account: string,amount: BigInt) {
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const gasPrice = await web3.eth.getGasPrice();
|
||||||
|
const gasLimit = 300000;
|
||||||
|
const tx = await clearnet_contract.methods.openPaymentChannel(amount).send({
|
||||||
|
from: account,
|
||||||
|
gas: String(gasLimit),
|
||||||
|
gasPrice: String(gasPrice),
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function closePaymentChannel(provider: any,account: string) {
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const gasPrice = await web3.eth.getGasPrice();
|
||||||
|
const gasLimit = 300000;
|
||||||
|
const tx = await clearnet_contract.methods.closePaymentChannel().send({
|
||||||
|
from: account,
|
||||||
|
gas: String(gasLimit),
|
||||||
|
gasPrice: String(gasPrice),
|
||||||
|
});
|
||||||
|
console.log(tx);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function processPayment(provider: any,account: string,nodeAddress: string,
|
||||||
|
vpnClientPublicKey: string, connectionStartTime: BigInt, agreedPricePerMinute: BigInt,
|
||||||
|
isRatingProvided: boolean, rating: BigInt, clientSignature: string, nodeSignature: string) {
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const gasPrice = await web3.eth.getGasPrice();
|
||||||
|
const gasLimit = 300000;
|
||||||
|
const tx = await clearnet_contract.methods.processPayment(
|
||||||
|
account,
|
||||||
|
nodeAddress,
|
||||||
|
vpnClientPublicKey,
|
||||||
|
connectionStartTime,
|
||||||
|
agreedPricePerMinute,
|
||||||
|
isRatingProvided,
|
||||||
|
rating,
|
||||||
|
clientSignature,
|
||||||
|
nodeSignature
|
||||||
|
).send({
|
||||||
|
from: account,
|
||||||
|
gas: String(gasLimit),
|
||||||
|
gasPrice: String(gasPrice),
|
||||||
|
});
|
||||||
|
console.log(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function abortConnection(provider: any,account: string,vpnClientPublicKey: string,
|
||||||
|
connectionStartTime: BigInt,agreedPricePerMinute: BigInt,clientSignature: Bytes) {
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const gasPrice = await web3.eth.getGasPrice();
|
||||||
|
const gasLimit = 300000;
|
||||||
|
const tx = await clearnet_contract.methods.abortConnection(
|
||||||
|
vpnClientPublicKey,
|
||||||
|
connectionStartTime,
|
||||||
|
agreedPricePerMinute,
|
||||||
|
clientSignature
|
||||||
|
).send({
|
||||||
|
from: account,
|
||||||
|
gas: String(gasLimit),
|
||||||
|
gasPrice: String(gasPrice),
|
||||||
|
});
|
||||||
|
console.log(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPaymentChannelInfo(provider: any,account: string) : Promise<PaymentChannelInfo> {
|
||||||
|
if (!provider) {
|
||||||
|
return { balance: BigInt(0), nonce: BigInt(0), isActive: false};
|
||||||
|
}
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const clearnet_contract = new web3.eth.Contract(clearNetABI, clearNetAddress);
|
||||||
|
const channelInfo: PaymentChannelInfo = await clearnet_contract.methods.getPaymentChannelInfo(account).call();
|
||||||
|
return {
|
||||||
|
balance: channelInfo.balance,
|
||||||
|
nonce: channelInfo.nonce,
|
||||||
|
isActive: channelInfo.isActive,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getNextNonce(provider: any,account: string) : Promise<BigInt> {
|
||||||
|
const channelInfo = await getPaymentChannelInfo(provider, account);
|
||||||
|
return channelInfo.nonce.valueOf() + BigInt(1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Button, Box, Typography, Alert } from "@mui/material";
|
||||||
|
import useAuth from '~/hooks/useAuth';
|
||||||
|
import { Web3 } from 'web3';
|
||||||
|
|
||||||
|
const FAUCET_ADDRESS = "0xA86b97D7CF0c00cd0e82bBDCe9F06d689cFb12b5";
|
||||||
|
|
||||||
|
const FAUCET_ABI = [
|
||||||
|
{
|
||||||
|
inputs: [],
|
||||||
|
name: "claim",
|
||||||
|
outputs: [],
|
||||||
|
stateMutability: "nonpayable",
|
||||||
|
type: "function",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function FaucetClaim() {
|
||||||
|
const [status, setStatus] = React.useState<string | null>(null);
|
||||||
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
const { auth } = useAuth();
|
||||||
|
const account = auth?.accounts?.[0];
|
||||||
|
const isAuthed = Boolean(account);
|
||||||
|
|
||||||
|
const claimFaucet = async () => {
|
||||||
|
if (!isAuthed) {
|
||||||
|
setStatus("Please connect your wallet first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setStatus("Preparing transaction...");
|
||||||
|
try {
|
||||||
|
const provider = auth.providerWithInfo.provider;
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const contract = new web3.eth.Contract(FAUCET_ABI, FAUCET_ADDRESS);
|
||||||
|
|
||||||
|
setStatus("Sending claim transaction...");
|
||||||
|
const tx = await contract.methods.claim().send({ from: account });
|
||||||
|
|
||||||
|
setStatus("Transaction Hash: " + tx.transactionHash + '\n' + "Claim confirmed. Check your balance.");
|
||||||
|
} catch (err: any) {
|
||||||
|
setStatus("Claim failed: " + (err?.message ?? String(err)));
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ fontFamily: "sans-serif", maxWidth: 640, margin: "24px auto", padding: "0 16px" }}>
|
||||||
|
<Typography variant="h5" gutterBottom>
|
||||||
|
CLR Faucet Claim
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography sx={{ mt: 1 }}>
|
||||||
|
Network: <strong>Sepolia</strong>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography sx={{ mt: 1 }}>
|
||||||
|
Faucet: <code>{FAUCET_ADDRESS}</code>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography sx={{ mt: 1 }}>
|
||||||
|
Token: <code>0xf1664c17887767c8f58695846babb349ca61d2e9</code>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Box sx={{ display: "flex", gap: 1, mt: 3 }}>
|
||||||
|
|
||||||
|
<Button variant="outlined" onClick={claimFaucet} disabled={loading || !isAuthed}>
|
||||||
|
{loading ? "Processing..." : "Claim CLR"}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{account && (
|
||||||
|
<Typography sx={{ mt: 2, fontSize: 13, color: "text.secondary" }}>
|
||||||
|
Connected: {account}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{status && (
|
||||||
|
<Alert severity="info" sx={{ mt: 2 }}>
|
||||||
|
{status}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -16,8 +16,6 @@ export const signMessage = async (message: string,provider: EIP1193Provider,user
|
|||||||
// For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
|
// For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
|
||||||
// This uses a Node.js-style buffer shim in the browser.
|
// This uses a Node.js-style buffer shim in the browser.
|
||||||
|
|
||||||
// const bytes = new TextEncoder().encode(String(publicKey));
|
|
||||||
// const msg = '0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
||||||
const msg = `0x${Buffer.from(message, "utf8").toString("hex")}`
|
const msg = `0x${Buffer.from(message, "utf8").toString("hex")}`
|
||||||
const sig = await provider.request({
|
const sig = await provider.request({
|
||||||
method: "personal_sign",
|
method: "personal_sign",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// ...existing code...
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useSyncProviders } from "./useSyncProviders";
|
import { useSyncProviders } from "./useSyncProviders";
|
||||||
import useAuth from "~/hooks/useAuth";
|
import useAuth from "~/hooks/useAuth";
|
||||||
@@ -123,4 +122,3 @@ export const DiscoverWalletProviders: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default DiscoverWalletProviders;
|
export default DiscoverWalletProviders;
|
||||||
// ...existing code...
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
// useSyncProviders.tsx
|
|
||||||
|
|
||||||
import { useSyncExternalStore } from "react";
|
import { useSyncExternalStore } from "react";
|
||||||
import { store } from "./store";
|
import { store } from "./store";
|
||||||
|
|
||||||
|
|||||||
+33
-10
@@ -1,20 +1,22 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { NavLink } from "react-router";
|
import { NavLink } from "react-router";
|
||||||
import AppBar from '@mui/material/AppBar';
|
import AppBar from '@mui/material/AppBar';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Toolbar from '@mui/material/Toolbar';
|
import Toolbar from '@mui/material/Toolbar';
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
|
|
||||||
import LoginIcon from "@mui/icons-material/Login";
|
import LoginIcon from "@mui/icons-material/Login";
|
||||||
import { Typography, Menu, MenuItem, IconButton, Avatar, Tooltip } from "@mui/material";
|
import { Typography, Menu, MenuItem, IconButton, Avatar, Tooltip } from "@mui/material";
|
||||||
import useAuth from "~/hooks/useAuth";
|
import useAuth from "~/hooks/useAuth";
|
||||||
import { signMessage } from './Metamask/Connections';
|
import type { PaymentChannelInfo } from './Util';
|
||||||
|
import { approveCLRTokenSpending, openPaymentChannel, closePaymentChannel, getPaymentChannelInfo } from './Contracts/Connections';
|
||||||
|
|
||||||
export default function ButtonAppBar() {
|
export default function ButtonAppBar() {
|
||||||
const { auth, setAuth } = useAuth();
|
const { auth, setAuth } = useAuth();
|
||||||
const account = auth?.accounts?.[0];
|
const account = auth?.accounts?.[0];
|
||||||
const isAuthed = Boolean(account);
|
const isAuthed = Boolean(account);
|
||||||
|
|
||||||
|
const [paymentChannelInfo, setPaymentChannelInfo] = React.useState<PaymentChannelInfo | null>(null);
|
||||||
|
const [registered, setRegistered] = React.useState<boolean>(false);
|
||||||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
const handleOpen = (e: React.MouseEvent<HTMLElement>) => setAnchorEl(e.currentTarget);
|
const handleOpen = (e: React.MouseEvent<HTMLElement>) => setAnchorEl(e.currentTarget);
|
||||||
@@ -28,14 +30,28 @@ export default function ButtonAppBar() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const register = async () => {
|
const register = async () => {
|
||||||
const sig = await signMessage("H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]);
|
const clr_deposit_amount = BigInt(100) * BigInt(1e18); // 100 CLR
|
||||||
try {
|
await approveCLRTokenSpending(auth.providerWithInfo.provider, account!);
|
||||||
const res_string = sig;
|
await openPaymentChannel(auth.providerWithInfo.provider, account!, clr_deposit_amount);
|
||||||
} catch (error) {
|
setRegistered(true);
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deRegister = async () => {
|
||||||
|
await closePaymentChannel(auth.providerWithInfo.provider, account!);
|
||||||
|
setRegistered(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getPaymentChannelInfo(auth.providerWithInfo ? auth.providerWithInfo.provider : undefined, account!).then((info) => {
|
||||||
|
setPaymentChannelInfo(info);
|
||||||
|
if(registered !== info.isActive) {
|
||||||
|
setRegistered(info.isActive);
|
||||||
|
}
|
||||||
|
console.log("Payment Channel Info:", info);
|
||||||
|
});
|
||||||
|
}, [account, auth.providerWithInfo?.provider,registered]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ flexGrow: 1 }}>
|
<Box sx={{ flexGrow: 1 }}>
|
||||||
<AppBar position="static">
|
<AppBar position="static">
|
||||||
@@ -51,6 +67,14 @@ export default function ButtonAppBar() {
|
|||||||
Home
|
Home
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
component={NavLink as any}
|
||||||
|
to="/faucet"
|
||||||
|
sx={{ color: 'inherit', textDecoration: 'none' }}
|
||||||
|
>
|
||||||
|
Faucet
|
||||||
|
</Typography>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
component={NavLink as any}
|
component={NavLink as any}
|
||||||
to="/about"
|
to="/about"
|
||||||
@@ -80,7 +104,6 @@ export default function ButtonAppBar() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{}
|
|
||||||
{isAuthed && (
|
{isAuthed && (
|
||||||
<>
|
<>
|
||||||
<Tooltip title={account ? `Account: ${account}` : "Account"}>
|
<Tooltip title={account ? `Account: ${account}` : "Account"}>
|
||||||
@@ -106,7 +129,7 @@ export default function ButtonAppBar() {
|
|||||||
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
|
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
|
||||||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={register}>Register</MenuItem>
|
{(paymentChannelInfo && paymentChannelInfo.isActive) ? (<MenuItem onClick={deRegister}>DeRegister</MenuItem>) : (<MenuItem onClick={register}>Register</MenuItem>)}
|
||||||
<MenuItem onClick={handleLogout}>Logout</MenuItem>
|
<MenuItem onClick={handleLogout}>Logout</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</>
|
</>
|
||||||
|
|||||||
+169
-64
@@ -2,86 +2,155 @@ import * as React from 'react';
|
|||||||
import ButtonGroup from '@mui/material/ButtonGroup';
|
import ButtonGroup from '@mui/material/ButtonGroup';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import Avatar from '@mui/material/Avatar';
|
import Avatar from '@mui/material/Avatar';
|
||||||
import { Grid, Card, CardContent, CardActions, Typography, Box, Chip, Dialog, DialogTitle, DialogContent, DialogActions, TextField } from "@mui/material";
|
import {
|
||||||
|
Grid,
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardActions,
|
||||||
|
Typography,
|
||||||
|
Box,
|
||||||
|
Chip,
|
||||||
|
Dialog,
|
||||||
|
DialogTitle,
|
||||||
|
DialogContent,
|
||||||
|
DialogActions,
|
||||||
|
IconButton,
|
||||||
|
Tooltip,
|
||||||
|
CircularProgress,
|
||||||
|
} from "@mui/material";
|
||||||
import ServerIcon from '@mui/icons-material/Dns';
|
import ServerIcon from '@mui/icons-material/Dns';
|
||||||
import SignalCellularAltIcon from '@mui/icons-material/SignalCellularAlt';
|
import SignalCellularAltIcon from '@mui/icons-material/SignalCellularAlt';
|
||||||
import AttachMoneyIcon from '@mui/icons-material/AttachMoney';
|
import AttachMoneyIcon from '@mui/icons-material/AttachMoney';
|
||||||
import StarIcon from '@mui/icons-material/Star';
|
import StarIcon from '@mui/icons-material/Star';
|
||||||
import Rating from '@mui/material/Rating';
|
import Rating from '@mui/material/Rating';
|
||||||
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||||
import useAuth from '~/hooks/useAuth';
|
import useAuth from '~/hooks/useAuth';
|
||||||
|
import type { AccountInfo } from '~/context/AuthProvider';
|
||||||
import { signMessage } from './Metamask/Connections';
|
import { signMessage } from './Metamask/Connections';
|
||||||
import { downloadWireguardConfig } from './WireguardConfig';
|
import { generateWireguardKeyPair, downloadWireguardConfig } from './WireguardConfig';
|
||||||
|
import type { Node } from './Util';
|
||||||
|
import { getActiveNodes, getNextNonce, processPayment, abortConnection } from './Contracts/Connections';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { Web3 } from 'web3';
|
||||||
|
|
||||||
interface Node {
|
|
||||||
ip: string;
|
|
||||||
traffic: number;
|
|
||||||
price : number;
|
|
||||||
rating : number;
|
|
||||||
}
|
|
||||||
|
|
||||||
function NodeItem({node}: {node: Node}) {
|
|
||||||
const port = 8080;
|
function NodeItem({node, auth}: {node: Node, auth: AccountInfo}) {
|
||||||
const { auth } = useAuth();
|
|
||||||
const [ratingOpen, setRatingOpen] = React.useState(false);
|
const [ratingOpen, setRatingOpen] = React.useState(false);
|
||||||
const [ratingValue, setRatingValue] = React.useState<number | null>(null);
|
const [ratingValue, setRatingValue] = React.useState<number | null>(null);
|
||||||
const [submittingRating, setSubmittingRating] = React.useState(false);
|
const [submittingRating, setSubmittingRating] = React.useState(false);
|
||||||
const getUrl = () => `http://${node.ip}:${port}`;
|
let nodeSignature = "";
|
||||||
|
const getUrl = () => `http://${node.ip}:${node.port}`;
|
||||||
const connect = async () => {
|
const connect = async () => {
|
||||||
// const publicKey = await getPublicKey(auth.providerWithInfo.provider, auth.accounts[0]);
|
|
||||||
try {
|
try {
|
||||||
const iv = await axios.get(getUrl() + "/connect");
|
const { privatekey: clientPrivateKey, publicKey: clientPublicKey } = generateWireguardKeyPair();
|
||||||
console.log(iv.data);
|
const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
const connectionStartTime = Math.floor(Date.now() / 1000);
|
||||||
const sig = await signMessage(iv.data + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]);
|
console.log("Nonce:", nonce.toString());
|
||||||
const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig;
|
const sig = await signMessage(nonce + clientPublicKey + connectionStartTime + node.pricePerMinute,auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
const res_string = nonce + '\n' + clientPublicKey + '\n' + connectionStartTime + '\n' + node.pricePerMinute + '\n' + sig;
|
||||||
let response = await axios.post(getUrl() + "/connect", res_string);
|
let response = await axios.post(getUrl() + "/connect", res_string);
|
||||||
|
const clientCIDR = response.data.WireguardClientCIDR;
|
||||||
|
const serverPublicKey = response.data.WireguardServerPublicKey;
|
||||||
|
const peerPort = response.data.WireguardPort;
|
||||||
|
const dns = response.data.WireguardDNS;
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
downloadWireguardConfig("", "", "", "", node.ip, "51820", "0.0.0.0/0");
|
if(response.data.NodeSignature){
|
||||||
|
const provider = auth.providerWithInfo.provider;
|
||||||
|
const web3 = new Web3(provider);
|
||||||
|
const recoveredAddress = web3.eth.accounts.recover(nonce.toString() + connectionStartTime + node.pricePerMinute, response.data.NodeSignature);
|
||||||
|
if(recoveredAddress === node.address){
|
||||||
|
nodeSignature = response.data.NodeSignature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(nodeSignature === ""){
|
||||||
|
await abortConnection(auth.providerWithInfo.provider, auth.accounts[0],
|
||||||
|
clientPublicKey,
|
||||||
|
BigInt(connectionStartTime),
|
||||||
|
node.pricePerMinute,
|
||||||
|
String(sig)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem(node.address, JSON.stringify({
|
||||||
|
vpnClientPublicKey: clientPublicKey,
|
||||||
|
connectionStartTime: connectionStartTime,
|
||||||
|
agreedPricePerMinute: node.pricePerMinute.toString(),
|
||||||
|
clientSignature: String(sig),
|
||||||
|
nodeSignature: nodeSignature
|
||||||
|
}));
|
||||||
|
downloadWireguardConfig(clientPrivateKey, serverPublicKey, clientCIDR, dns, node.ip, String(peerPort), "0.0.0.0/0");
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendPayment = async (isRatingProvided: boolean, rating: BigInt) => {
|
||||||
|
try{
|
||||||
|
const storedInfo = localStorage.getItem(node.address);
|
||||||
|
if(!storedInfo){
|
||||||
|
console.error("No active connection info");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const connectionInfo = JSON.parse(storedInfo);
|
||||||
|
if (isRatingProvided) {
|
||||||
|
const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
connectionInfo.clientSignature = await signMessage(nonce + connectionInfo.vpnClientPublicKey + connectionInfo.connectionStartTime + connectionInfo.agreedPricePerMinute + rating,auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
localStorage.setItem(node.address,JSON.stringify(connectionInfo))
|
||||||
|
}
|
||||||
|
await processPayment(auth.providerWithInfo.provider, auth.accounts[0],
|
||||||
|
node.address,
|
||||||
|
connectionInfo.vpnClientPublicKey,
|
||||||
|
BigInt(connectionInfo.connectionStartTime),
|
||||||
|
BigInt(connectionInfo.agreedPricePerMinute),
|
||||||
|
isRatingProvided,
|
||||||
|
rating,
|
||||||
|
connectionInfo.clientSignature,
|
||||||
|
connectionInfo.nodeSignature
|
||||||
|
);
|
||||||
|
localStorage.removeItem(node.address);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const disconnect = async () => {
|
const disconnect = async () => {
|
||||||
try{
|
// try{
|
||||||
const iv = await axios.get(getUrl() + "/disconnect");
|
// const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
console.log(iv.data);
|
// const sig = await signMessage(String(nonce),auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
// const res_string = String(nonce) + '\n' + sig;
|
||||||
const sig = await signMessage(iv.data,auth.providerWithInfo.provider, auth.accounts[0]);
|
// let response = await axios.post(getUrl() + "/disconnect", res_string);
|
||||||
const res_string = iv.data + '\n' + sig;
|
// console.log(response.data);
|
||||||
let response = await axios.post(getUrl() + "/disconnect", res_string);
|
// } catch (error) {
|
||||||
console.log(response.data);
|
// console.error('Error:', error);
|
||||||
} catch (error) {
|
// }
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
|
||||||
setRatingOpen(true);
|
setRatingOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleNoRating = () => {
|
||||||
|
console.log("no rating");
|
||||||
|
sendPayment(false, BigInt(0));
|
||||||
|
handleCloseRating()
|
||||||
|
}
|
||||||
|
|
||||||
const handleCloseRating = () => {
|
const handleCloseRating = () => {
|
||||||
setRatingOpen(false);
|
setRatingOpen(false);
|
||||||
setRatingValue(null);
|
setRatingValue(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitRating = async () => {
|
const handleSubmitRating = () => {
|
||||||
if (ratingValue == null) {
|
if (ratingValue == null) {
|
||||||
|
console.log("no rating value");
|
||||||
|
sendPayment(false, BigInt(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("submit rating:", ratingValue);
|
||||||
setSubmittingRating(true);
|
setSubmittingRating(true);
|
||||||
try {
|
sendPayment(true, BigInt(ratingValue));
|
||||||
await axios.post('http://' + node.ip + ":8080/rate", {
|
|
||||||
rating: ratingValue,
|
|
||||||
}, {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
});
|
|
||||||
console.log('Rating submitted');
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to submit rating', err);
|
|
||||||
} finally {
|
|
||||||
setSubmittingRating(false);
|
setSubmittingRating(false);
|
||||||
handleCloseRating();
|
handleCloseRating();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid size={{ xs: 12, sm: 6, md: 4 }}>
|
<Grid size={{ xs: 12, sm: 6, md: 4 }}>
|
||||||
@@ -158,7 +227,7 @@ function NodeItem({node}: {node: Node}) {
|
|||||||
</CardActions>
|
</CardActions>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={ratingOpen} onClose={handleCloseRating}>
|
<Dialog open={ratingOpen} onClose={handleNoRating}>
|
||||||
<DialogTitle>Rate this server</DialogTitle>
|
<DialogTitle>Rate this server</DialogTitle>
|
||||||
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 320 }}>
|
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 320 }}>
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
@@ -171,7 +240,7 @@ function NodeItem({node}: {node: Node}) {
|
|||||||
</Box>
|
</Box>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleCloseRating} disabled={submittingRating}>Cancel</Button>
|
<Button onClick={handleNoRating} disabled={submittingRating}>Cancel</Button>
|
||||||
<Button onClick={handleSubmitRating} disabled={submittingRating || ratingValue == null} variant="contained">Submit</Button>
|
<Button onClick={handleSubmitRating} disabled={submittingRating || ratingValue == null} variant="contained">Submit</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
@@ -180,33 +249,69 @@ function NodeItem({node}: {node: Node}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function FolderList() {
|
export default function FolderList() {
|
||||||
const [nodes, setNodes] = React.useState<Node[]>([
|
const { auth } = useAuth();
|
||||||
{ ip: "57.158.82.48", traffic: 5, price: 10, rating: 3 },
|
const [nodes, setNodes] = React.useState<Node[]>([]);
|
||||||
{ ip: "8.210.33.199", traffic: 3, price: 15, rating: 4 },
|
const [loading, setLoading] = React.useState(false);
|
||||||
{ ip: "45.77.12.5", traffic: 7, price: 20, rating: 5 },
|
const fetchNodes = React.useCallback(async () => {
|
||||||
{ ip: "203.120.45.78", traffic: 2, price: 8, rating: 2 },
|
setLoading(true);
|
||||||
{ ip: "91.189.88.25", traffic: 6, price: 12, rating: 4 },
|
try {
|
||||||
{ ip: "132.148.9.201", traffic: 9, price: 18, rating: 5 },
|
const provider = auth?.providerWithInfo?.provider;
|
||||||
{ ip: "60.12.180.99", traffic: 4, price: 14, rating: 3 },
|
const fetchedNodes = await getActiveNodes(provider);
|
||||||
{ ip: "199.59.243.100", traffic: 1, price: 6, rating: 1 },
|
setNodes(fetchedNodes);
|
||||||
{ ip: "34.216.77.3", traffic: 8, price: 22, rating: 5 },
|
} catch (err) {
|
||||||
{ ip: "185.199.108.153", traffic: 5, price: 11, rating: 4 },
|
console.error("Failed to fetch nodes", err);
|
||||||
{ ip: "13.107.21.200", traffic: 7, price: 16, rating: 4 },
|
} finally {
|
||||||
{ ip: "216.58.214.14", traffic: 3, price: 9, rating: 2 },
|
setLoading(false);
|
||||||
{ ip: "104.21.44.33", traffic: 10, price: 25, rating: 5 },
|
}
|
||||||
{ ip: "47.90.12.201", traffic: 2, price: 7, rating: 1 },
|
}, [auth]);
|
||||||
{ ip: "23.45.67.89", traffic: 6, price: 13, rating: 3 },
|
|
||||||
{ ip: "192.0.2.123", traffic: 4, price: 17, rating: 4 },
|
useEffect(() => {
|
||||||
]);
|
fetchNodes();
|
||||||
|
}, [fetchNodes]);
|
||||||
|
// const [nodes, setNodes] = React.useState<Node[]>([
|
||||||
|
// { ip: "57.158.82.48", traffic: 5, price: 10, rating: 3 },
|
||||||
|
// { ip: "8.210.33.199", traffic: 3, price: 15, rating: 4 },
|
||||||
|
// { ip: "45.77.12.5", traffic: 7, price: 20, rating: 5 },
|
||||||
|
// { ip: "203.120.45.78", traffic: 2, price: 8, rating: 2 },
|
||||||
|
// { ip: "91.189.88.25", traffic: 6, price: 12, rating: 4 },
|
||||||
|
// { ip: "132.148.9.201", traffic: 9, price: 18, rating: 5 },
|
||||||
|
// { ip: "60.12.180.99", traffic: 4, price: 14, rating: 3 },
|
||||||
|
// { ip: "199.59.243.100", traffic: 1, price: 6, rating: 1 },
|
||||||
|
// { ip: "34.216.77.3", traffic: 8, price: 22, rating: 5 },
|
||||||
|
// { ip: "185.199.108.153", traffic: 5, price: 11, rating: 4 },
|
||||||
|
// { ip: "13.107.21.200", traffic: 7, price: 16, rating: 4 },
|
||||||
|
// { ip: "216.58.214.14", traffic: 3, price: 9, rating: 2 },
|
||||||
|
// { ip: "104.21.44.33", traffic: 10, price: 25, rating: 5 },
|
||||||
|
// { ip: "47.90.12.201", traffic: 2, price: 7, rating: 1 },
|
||||||
|
// { ip: "23.45.67.89", traffic: 6, price: 13, rating: 3 },
|
||||||
|
// { ip: "192.0.2.123", traffic: 4, price: 17, rating: 4 },
|
||||||
|
// ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ flexGrow: 1, p: 3 }}>
|
<Box sx={{ flexGrow: 1, p: 3 }}>
|
||||||
<Typography variant="h4" gutterBottom component="div" sx={{ mb: 4, fontWeight: 'bold' }}>
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 3 }}>
|
||||||
|
<Typography variant="h4" component="div" sx={{ fontWeight: 'bold' }}>
|
||||||
Available Servers
|
Available Servers
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
<Tooltip title="Refresh servers">
|
||||||
|
<span>
|
||||||
|
<IconButton
|
||||||
|
onClick={fetchNodes}
|
||||||
|
disabled={loading || auth?.providerWithInfo === undefined}
|
||||||
|
color="primary"
|
||||||
|
aria-label="refresh servers"
|
||||||
|
>
|
||||||
|
{loading ? <CircularProgress size={20} /> : <RefreshIcon />}
|
||||||
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
<Grid container spacing={3}>
|
<Grid container spacing={3}>
|
||||||
{nodes.map((node, index) => (
|
{nodes.map((node, index) => (
|
||||||
<NodeItem key={index} node={node} />
|
<NodeItem key={index} node={node} auth={auth}/>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
export interface Node {
|
||||||
|
address: string;
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
traffic: number;
|
||||||
|
price : number;
|
||||||
|
pricePerMinute : BigInt;
|
||||||
|
rating : number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NodeInfo {
|
||||||
|
ipAddress: string;
|
||||||
|
port: number;
|
||||||
|
pricePerMinute : BigInt;
|
||||||
|
reputationScore : BigInt;
|
||||||
|
totalMinutesServed : BigInt;
|
||||||
|
totalEarnings : BigInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PaymentChannelInfo {
|
||||||
|
balance: BigInt;
|
||||||
|
nonce: BigInt;
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
||||||
@@ -1,13 +1,56 @@
|
|||||||
|
import nacl from "tweetnacl";
|
||||||
|
|
||||||
|
function bytesToBase64(bytes: Uint8Array) {
|
||||||
|
let binary = '';
|
||||||
|
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
||||||
|
return btoa(binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
function base64ToBytes(base64: string): Uint8Array {
|
||||||
|
// support URL-safe base64
|
||||||
|
base64 = base64.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
|
// pad to multiple of 4
|
||||||
|
const pad = base64.length % 4;
|
||||||
|
if (pad) base64 += "=".repeat(4 - pad);
|
||||||
|
|
||||||
|
const binary = atob(base64);
|
||||||
|
const len = binary.length;
|
||||||
|
const bytes = new Uint8Array(len);
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
bytes[i] = binary.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateWireGuardPrivateKey = () => {
|
||||||
|
// const privateKeyBytes = utils.randomPrivateKey();
|
||||||
|
// const privateKeyBase64 = bytesToBase64(privateKeyBytes);
|
||||||
|
const privateKey = nacl.randomBytes(32);
|
||||||
|
|
||||||
|
return bytesToBase64(privateKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getWireguardPublicKey = (privateKey: string) => {
|
||||||
|
const privateKeyBytes = base64ToBytes(privateKey);
|
||||||
|
const publicKey = nacl.scalarMult.base(privateKeyBytes);
|
||||||
|
return bytesToBase64(publicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateWireguardKeyPair = () => {
|
||||||
|
const privatekey = generateWireGuardPrivateKey();
|
||||||
|
const publicKey = getWireguardPublicKey(privatekey);
|
||||||
|
return { privatekey, publicKey };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const downloadWireguardConfig = async (clientPrivateKey: string, serverPubcliKey: string ,localCIDR: string, dns: string, peerIp: string, peerPort: string, allowedIPs: string) => {
|
||||||
|
|
||||||
export const downloadWireguardConfig = (privateKey: string, publicKey: string, localCIDR: string, dns: string, peerIp: string, peerPort: string, allowedIPs: string) => {
|
|
||||||
const content = `[Interface]`+'\n'+
|
const content = `[Interface]`+'\n'+
|
||||||
`PrivateKey = ${privateKey}`+'\n'+
|
`PrivateKey = ${clientPrivateKey}`+'\n'+
|
||||||
`Address = ${localCIDR}`+'\n'+
|
`Address = ${localCIDR}`+'\n'+
|
||||||
`DNS = ${dns}`+'\n'+
|
`DNS = ${dns}`+'\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
`[Peer]`+'\n'+
|
`[Peer]`+'\n'+
|
||||||
`PublicKey = ${publicKey}`+'\n'+
|
`PublicKey = ${serverPubcliKey}`+'\n'+
|
||||||
`AllowedIPs = ${allowedIPs}`+'\n'+
|
`AllowedIPs = ${allowedIPs}`+'\n'+
|
||||||
`Endpoint = ${peerIp}:${peerPort}`;
|
`Endpoint = ${peerIp}:${peerPort}`;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>CLR Faucet Claim</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: sans-serif; max-width: 640px; margin: 24px auto; padding: 0 16px; }
|
||||||
|
button { padding: 10px 16px; font-size: 16px; cursor: pointer; }
|
||||||
|
.row { margin: 12px 0; }
|
||||||
|
#status { margin-top: 12px; white-space: pre-line; }
|
||||||
|
code { background: #f4f4f4; padding: 2px 4px; border-radius: 4px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>CLR Faucet Claim</h2>
|
||||||
|
<div class="row">Network: <strong>Sepolia</strong></div>
|
||||||
|
<div class="row">Faucet: <code id="faucetAddr">0xA86b97D7CF0c00cd0e82bBDCe9F06d689cFb12b5</code></div>
|
||||||
|
<div class="row">Token: <code>0xf1664c17887767c8f58695846babb349ca61d2e9</code></div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<button id="connect">Connect Wallet</button>
|
||||||
|
<button id="claim" disabled>Claim 100 CLR</button>
|
||||||
|
</div>
|
||||||
|
<div id="status"></div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/ethers@6.13.1/dist/ethers.umd.min.js"></script>
|
||||||
|
<script>
|
||||||
|
// Check if ethers loaded
|
||||||
|
if (typeof ethers === 'undefined') {
|
||||||
|
document.getElementById("status").textContent = "Error: ethers.js failed to load. Check internet connection.";
|
||||||
|
throw new Error("ethers.js not loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- CONFIG ----------------------
|
||||||
|
const FAUCET_ADDRESS = "0xA86b97D7CF0c00cd0e82bBDCe9F06d689cFb12b5"; // set your deployed faucet address
|
||||||
|
const FAUCET_ABI = ["function claim() external"];
|
||||||
|
// ----------------------------------------------------
|
||||||
|
|
||||||
|
const statusEl = document.getElementById("status");
|
||||||
|
const connectBtn = document.getElementById("connect");
|
||||||
|
const claimBtn = document.getElementById("claim");
|
||||||
|
document.getElementById("faucetAddr").textContent = FAUCET_ADDRESS;
|
||||||
|
|
||||||
|
function log(msg) {
|
||||||
|
statusEl.textContent = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connect() {
|
||||||
|
if (!window.ethereum) {
|
||||||
|
log("Please install MetaMask.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
log("Connecting wallet...");
|
||||||
|
await window.ethereum.request({ method: "eth_requestAccounts" });
|
||||||
|
const provider = new ethers.BrowserProvider(window.ethereum);
|
||||||
|
const network = await provider.getNetwork();
|
||||||
|
if (network.chainId !== 11155111n) {
|
||||||
|
log("Please switch MetaMask to Sepolia.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log("Wallet connected on Sepolia.");
|
||||||
|
claimBtn.disabled = false;
|
||||||
|
return provider;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
log("Connect failed: " + (err?.message || err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function claim() {
|
||||||
|
try {
|
||||||
|
claimBtn.disabled = true;
|
||||||
|
log("Sending claim transaction...");
|
||||||
|
const provider = new ethers.BrowserProvider(window.ethereum);
|
||||||
|
const signer = await provider.getSigner();
|
||||||
|
const faucet = new ethers.Contract(FAUCET_ADDRESS, FAUCET_ABI, signer);
|
||||||
|
const tx = await faucet.claim();
|
||||||
|
log("Pending tx: " + tx.hash + "\nWaiting for confirmation...");
|
||||||
|
await tx.wait();
|
||||||
|
log("✅ Claim confirmed! Tx: " + tx.hash);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
log("Claim failed: " + (err?.shortMessage || err?.message || err));
|
||||||
|
} finally {
|
||||||
|
claimBtn.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connectBtn.onclick = connect;
|
||||||
|
claimBtn.onclick = claim;
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+2
-1
@@ -3,5 +3,6 @@ import { type RouteConfig, index, route } from "@react-router/dev/routes";
|
|||||||
export default [
|
export default [
|
||||||
index("routes/home.tsx"),
|
index("routes/home.tsx"),
|
||||||
route("wallets", "routes/wallets.tsx"),
|
route("wallets", "routes/wallets.tsx"),
|
||||||
route("about", "routes/about.tsx")
|
route("about", "routes/about.tsx"),
|
||||||
|
route("faucet", "routes/faucet.tsx")
|
||||||
] satisfies RouteConfig;
|
] satisfies RouteConfig;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import FaucetClaim from "~/Components/Faucet";
|
||||||
|
|
||||||
|
export default function FaucetPage() {
|
||||||
|
return(
|
||||||
|
<FaucetClaim />
|
||||||
|
);
|
||||||
|
}
|
||||||
Generated
+837
-7
File diff suppressed because it is too large
Load Diff
+3
-1
@@ -20,7 +20,9 @@
|
|||||||
"isbot": "^5.1.31",
|
"isbot": "^5.1.31",
|
||||||
"react": "^19.1.1",
|
"react": "^19.1.1",
|
||||||
"react-dom": "^19.1.1",
|
"react-dom": "^19.1.1",
|
||||||
"react-router": "^7.9.2"
|
"react-router": "^7.9.2",
|
||||||
|
"tweetnacl": "^1.0.3",
|
||||||
|
"web3": "^4.16.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-router/dev": "^7.9.2",
|
"@react-router/dev": "^7.9.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user