Skip to content

Commit

Permalink
🔨 Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Jun 18, 2024
1 parent 0a8769a commit f27d875
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
32 changes: 17 additions & 15 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 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

Expand All @@ -32,11 +32,13 @@ cd lsk-faucet
```

2. Bundle Frontend web with Vite
Please make sure to replace token icon at `web/public/token.png` with the specific ERC20 token icon.

```bash
go generate
```

3. Build Go project
1. Build Go project
```bash
go build -o lsk-faucet
```
Expand All @@ -58,12 +60,12 @@ go build -o lsk-faucet
### 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
Expand All @@ -86,17 +88,17 @@ Then run the faucet application without the wallet command-line 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
Expand Down
4 changes: 2 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ 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")
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")
Expand Down
4 changes: 2 additions & 2 deletions internal/chain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *Server) handleClaim() http.HandlerFunc {
address, _ := readAddress(r)
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()
txHash, err := s.TransferLSK(ctx, address, chain.LSKToWei(int64(s.cfg.payout)))
txHash, err := s.TransferERC20(ctx, address, chain.LSKToWei(int64(s.cfg.payout)))
if err != nil {
log.WithError(err).Error("Failed to send transaction")
renderJSON(w, claimResponse{Message: err.Error()}, http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/favicon.png" />
<link rel="icon" type="image/png" href="/token.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte</title>
</head>
Expand Down
File renamed without changes

0 comments on commit f27d875

Please sign in to comment.