Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UI #5

Merged
merged 8 commits into from
Jun 19, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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
@@ -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 custom ERC20 tokens on any network. The tokens can be used to test and troubleshoot your decentralized application or protocol before going live on the Mainnet.

## Features

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

2. Bundle Frontend web with Vite

**NOTE**: Please make sure to replace token icon at `web/public/token.png` with the specific ERC20 token icon.

```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.
- `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 ERC20 token on the above mentioned network, defaults to Lisk L2 token address.

You can configure the funder by setting any of the following environment variable instead of command-line flags:
```bash
@@ -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.
6 changes: 3 additions & 3 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -19,14 +19,14 @@ 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")
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")
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", "sepolia", "Network name to display on the frontend")
symbolFlag = flag.String("faucet.symbol", "LSK", "Token symbol to display on the frontend")

6 changes: 3 additions & 3 deletions internal/chain/transaction.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import (
type TxBuilder interface {
Sender() common.Address
TransferETH(ctx context.Context, to string, value *big.Int) (common.Hash, error)
TransferLSK(ctx context.Context, to string, value *big.Int) (common.Hash, error)
TransferERC20(ctx context.Context, to string, value *big.Int) (common.Hash, error)
}

type TxBuild struct {
@@ -96,7 +96,7 @@ func (b *TxBuild) TransferETH(ctx context.Context, to string, value *big.Int) (c
return signedTx.Hash(), nil
}

func (b *TxBuild) TransferLSK(ctx context.Context, to string, value *big.Int) (common.Hash, error) {
func (b *TxBuild) TransferERC20(ctx context.Context, to string, value *big.Int) (common.Hash, error) {
emptyHash := common.Hash{}
publicKey := b.privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
@@ -149,7 +149,7 @@ func (b *TxBuild) TransferLSK(ctx context.Context, to string, value *big.Int) (c
if err = b.client.SendTransaction(ctx, signedTx); err != nil {
log.Error("failed to send tx", "tx hash", signedTx.Hash().String(), "err", err)
if strings.Contains(err.Error(), "nonce") {
b.refreshNonce(context.Background())
b.refreshNonce(ctx)
}
return emptyHash, err
}
Loading