Skip to content

Commit

Permalink
Update UI (#5)
Browse files Browse the repository at this point in the history
* 🌱 Update UI

* Add unit tests

* 🔨 Code refactoring

* 🌱 Add Makefile

* Add workflow file

* 👌 Applied suggestions

* 👌 Applied suggestions

* Add unit test for TransferERC20 method
  • Loading branch information
nagdahimanshu authored Jun 19, 2024
1 parent 0c59d9a commit 465997e
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 188 deletions.
60 changes: 0 additions & 60 deletions .github/workflows/build.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/docker.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: 'PR CI'

on:
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: build
run: make build
- name: golangci-lint
run: make lint
- name: format
run: |
make format
if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
echo "All files formatted"
else
echo "Running format is required"
exit 1
fi
- name: test
run: make test
33 changes: 0 additions & 33 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 5m
skip-dirs:
exclude-dirs:
- .github
- web

Expand Down
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

APP_NAME = lsk-faucet
PKGS=$(shell go list ./... | grep -v "/vendor/")
BLUE = \033[1;34m
GREEN = \033[1;32m
COLOR_END = \033[0;39m

build: build-frontend build-backend

build-backend: # Builds the application and create a binary at ./bin/
@echo "$(BLUE)» Building $(APP_NAME) application binary... $(COLOR_END)"
@go build -a -o bin/$(APP_NAME) .
@echo "$(GREEN)Binary successfully built$(COLOR_END)"

build-frontend: # Builds the frontned application
@echo "$(BLUE)» Building frontend... $(COLOR_END)"
@go generate
@echo "$(GREEN)Frontend successfully built$(COLOR_END)"

run: # Runs the application, use `make run FLAGS="--help"`
@./bin/${APP_NAME} ${FLAGS}

test: # Runs tests
@echo "Test packages"
@go test -race -shuffle=on -coverprofile=coverage.out -cover $(PKGS)

lint: # Runs golangci-lint on the repo
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run

format: # Runs gofmt on the repo
gofmt -s -w .

build-image: # Builds docker image
@echo "$(BLUE)Building docker image...$(COLOR_END)"
@docker build -t $(APP_NAME) .

docker-start: # Runs docker image
@echo "$(BLUE)Starting docker container $(APP_NAME)...$(COLOR_END)"
ifdef PRIVATE_KEY
@docker run --name $(APP_NAME) -p 8080:8080 -d -e WEB3_PROVIDER=$(WEB3_PROVIDER) -e PRIVATE_KEY=$(PRIVATE_KEY) $(APP_NAME)
else ifdef KEYSTORE
@docker run --name $(APP_NAME) -p 8080:8080 -d -e WEB3_PROVIDER=$(WEB3_PROVIDER) -e KEYSTORE=$(KEYSTORE) -v $(KEYSTORE)/keystore:/app/keystore -v $(KEYSTORE)/password.txt:/app/password.txt $(APP_NAME)
endif

docker-stop:
@echo "$(BLUE)Stopping and removing docker container $(APP_NAME)...$(COLOR_END)"
@docker rm -f $(APP_NAME)

.PHONY: help
help: # Show help for each of the Makefile recipes
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "$(GREEN)$$(echo $$l | cut -f 1 -d':')$(COLOR_END):$$(echo $$l | cut -f 2- -d'#')\n"; done
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
![GitHub issues](https://img.shields.io/github/issues-raw/liskhq/lsk-faucet)
![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/liskhq/lsk-faucet)

LSK faucet is a web application to get Lisk (LSK) tokens on the Lisk Sepolia Testnet. The tokens can be used to test and troubleshoot your decentralized application or protocol before going live on the Lisk Mainnet.
LSK faucet is a web application that can be configured and deployed to get ETH and custom ERC20 tokens on any test network. The tokens can be used to test and troubleshoot your decentralized application or protocol before going live on the Mainnet.

## Features

Expand All @@ -32,38 +32,41 @@ cd lsk-faucet
```

2. Bundle Frontend web with Vite

**NOTE**: Please make sure to update the token icon under `web/public/` with the specific ERC20 token icon. The file must be named `token.png`. We recommend the image dimensions to be 128px x 128px.

```bash
go generate
make build-frontend
```

3. Build Go project
```bash
go build -o lsk-faucet
make build-backend
```

## Usage

**Use private key to fund users**

```bash
./lsk-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.privkey privkey
make run FLAGS="-httpport 8080 -wallet.provider http://localhost:8545 -wallet.privkey privkey"
```

**Use keystore to fund users**

```bash
./lsk-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.keyjson keystore -wallet.keypass password.txt
make run FLAGS="-httpport 8080 -wallet.provider http://localhost:8545 -wallet.keyjson keystore -wallet.keypass password.txt"
```

### Configuration
Below is a list of environment variables that can be configured.

- `WEB3_PROVIDER`: Endpoint for Lisk JSON-RPC connection.
- `WEB3_PROVIDER`: RPC Endpoint to connect with the network node.
- `PRIVATE_KEY`: Private key hex to fund user requests with.
- `KEYSTORE`: Keystore file to fund user requests with.
- `HCAPTCHA_SITEKEY`: hCaptcha sitekey.
- `HCAPTCHA_SECRET`: hCaptcha secret.
- `LSK_TOKEN_ADDRESS`: Contract address of LSK token on the Lisk L2.
- `ERC20_TOKEN_ADDRESS`: Contract address of the ERC20 token on the configured network, defaults to contract address for Lisk ERC20 tokens on Lisk Sepolia.

You can configure the funder by setting any of the following environment variable instead of command-line flags:
```bash
Expand All @@ -79,46 +82,45 @@ echo "your keystore password" > `pwd`/password.txt

Then run the faucet application without the wallet command-line flags:
```bash
./lsk-faucet -httpport 8080
make run FLAGS="-httpport 8080"
```

**Optional Flags**

The following are the available command-line flags(excluding above wallet flags):

| Flag | Description | Default Value |
| ----------------- | ------------------------------------------------ | ------------------------------------------ |
| -httpport | Listener port to serve HTTP connection | 8080 |
| -proxycount | Count of reverse proxies in front of the server | 0 |
| -token-address | Token contract address | 0x8a21CF9Ba08Ae709D64Cb25AfAA951183EC9FF6D |
| -faucet.amount | Number of LSK to transfer per user request | 1 |
| -faucet.minutes | Number of minutes to wait between funding rounds | 10080 (1 week) |
| -faucet.name | Network name to display on the frontend | sepolia |
| -faucet.symbol | Token symbol to display on the frontend | LSK |
| -hcaptcha.sitekey | hCaptcha sitekey | |
| -hcaptcha.secret | hCaptcha secret | |
| Flag | Description | Default Value |
| ----------------- | --------------------------------------------------- | ------------------------------------------ |
| -httpport | Listener port to serve HTTP connection | 8080 |
| -proxycount | Count of reverse proxies in front of the server | 0 |
| -token-address | Token contract address | 0x8a21CF9Ba08Ae709D64Cb25AfAA951183EC9FF6D |
| -faucet.amount | Number of ERC20 tokens to transfer per user request | 1 |
| -faucet.minutes | Number of minutes to wait between funding rounds | 10080 (1 week) |
| -faucet.name | Network name to display on the frontend | sepolia |
| -faucet.symbol | Token symbol to display on the frontend | LSK |
| -hcaptcha.sitekey | hCaptcha sitekey | |
| -hcaptcha.secret | hCaptcha secret | |

### Docker deployment
#### Build docker image
Run the following command to build docker image:
```bash
docker build -t liskhq/lsk-faucet .
make build
```


#### Run faucet
Run the following command to start the application:

```bash
docker run -d -p 8080:8080 -e WEB3_PROVIDER=<rpc-endpoint> -e PRIVATE_KEY=<hex-private-key> liskhq/lsk-faucet
make docker-start WEB3_PROVIDER=<rpc-endpoint> PRIVATE_KEY=<hex-private-key>

```
**NOTE**: Please replace `<rpc-endpoint>` and `<hex-private-key>` with appropriate values.

or

```bash
docker run -d -p 8080:8080 -e WEB3_PROVIDER=<rpc-endpoint> -e KEYSTORE=<keystore-path> -v `pwd`/keystore:/app/keystore -v `pwd`/password.txt:/app/password.txt liskhq/lsk-faucet
make docker-start WEB3_PROVIDER=<rpc-endpoint> KEYSTORE=<keystore-path>
```

**NOTE**: Please replace `<rpc-endpoint>` and `<keystore-path>` with appropriate values.
Expand Down
13 changes: 7 additions & 6 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import (
)

var (
appVersion = "v1.1.0"
chainIDMap = map[string]int{"sepolia": 4202}
tokenAddress = flag.String("token-address", os.Getenv("LSK_TOKEN_ADDRESS"), "Contract address of LSK token on the Lisk L2")
appVersion = "v1.1.0"
chainIDMap = map[string]int{"lisk_sepolia": 4202}

tokenAddress = flag.String("token-address", os.Getenv("ERC20_TOKEN_ADDRESS"), "Contract address of ERC20 token")

httpPortFlag = flag.Int("httpport", 8080, "Listener port to serve HTTP connection")
proxyCntFlag = flag.Int("proxycount", 0, "Count of reverse proxies in front of the server")
versionFlag = flag.Bool("version", false, "Print version number")

payoutFlag = flag.Int("faucet.amount", 1, "Number of LSK to transfer per user request")
intervalFlag = flag.Int("faucet.minutes", 1440, "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet.name", "sepolia", "Network name to display on the frontend")
payoutFlag = flag.Int("faucet.amount", 1, "Number of ERC20 tokens to transfer per user request")
intervalFlag = flag.Int("faucet.minutes", 10080, "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet.name", "lisk_sepolia", "Network name to display on the frontend")
symbolFlag = flag.String("faucet.symbol", "LSK", "Token symbol to display on the frontend")

keyJSONFlag = flag.String("wallet.keyjson", os.Getenv("KEYSTORE"), "Keystore file to fund user requests with")
Expand Down
Loading

0 comments on commit 465997e

Please sign in to comment.