Skip to content

Commit

Permalink
Fix estimate gas logic (#8)
Browse files Browse the repository at this point in the history
* 🐛 Fix estimate gas calculation

* Add command to generate Go binding in Makefile
Update readme

* 👌 Applied suggestions

* 👌 Applied suggestions from code review
  • Loading branch information
nagdahimanshu authored Jun 21, 2024
1 parent 465997e commit af94b98
Show file tree
Hide file tree
Showing 8 changed files with 1,850 additions and 82 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
WEB3_PROVIDER=
PRIVATE_KEY=
KEYSTORE=
ERC20_TOKEN_ADDRESS=
HCAPTCHA_SITEKEY=
HCAPTCHA_SECRET=
33 changes: 25 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
include .env

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

validate-env: # Validates if the necessary environment variables are set
ifndef ERC20_CONTRACT_FILE_PATH
$(error `ERC20_CONTRACT_FILE_PATH` environment variable is undefined)
endif

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) .
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
go generate
@echo "$(GREEN)Frontend successfully built$(COLOR_END)"

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

generate-abi: validate-env
@echo "$(BLUE)Generating abi file... $(COLOR_END)"
solc --overwrite --abi $(ERC20_CONTRACT_FILE_PATH) -o $(BINDING_OUTPUT_DIR)
@echo "$(GREEN)ABI file generated successfully$(COLOR_END)"

generate-binding: generate-abi
@echo "$(BLUE)Generating go binding for the ERC20 token smart contract... $(COLOR_END)"
abigen --abi=$(shell find $(BINDING_OUTPUT_DIR) -type f -name '*.abi') --pkg=bindings --out=$(BINDING_OUTPUT_DIR)/erc20.go
@echo "$(GREEN)Go binding generated successfully$(COLOR_END)"

test: # Runs tests
@echo "Test packages"
@go test -race -shuffle=on -coverprofile=coverage.out -cover $(PKGS)
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
Expand All @@ -33,19 +50,19 @@ format: # Runs gofmt on the repo

build-image: # Builds docker image
@echo "$(BLUE)Building docker image...$(COLOR_END)"
@docker build -t $(APP_NAME) .
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)
docker run --name $(APP_NAME) -p 8080:8080 -d --env-file .env $(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)
docker run --name $(APP_NAME) -p 8080:8080 -d --env-file .env -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)
docker rm -f $(APP_NAME)

.PHONY: help
help: # Show help for each of the Makefile recipes
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ LSK faucet is a web application that can be configured and deployed to get ETH a

* Go (1.22 or later)
* Node.js
* Solidity compiler (solc)
* Abigen

### Installation

Expand All @@ -38,8 +40,14 @@ cd lsk-faucet
```bash
make build-frontend
```
3. Generate Go binding for ERC20 token smart contract
```bash
make generate-binding ERC20_CONTRACT_FILE_PATH=<erc20-contract-file-path>
```

**NOTE**: Please make sure to generate the Go binding corresponding to your contract before building the project.

3. Build Go project
4. Build Go project
```bash
make build-backend
```
Expand Down Expand Up @@ -105,25 +113,16 @@ The following are the available command-line flags(excluding above wallet flags)
#### Build docker image
Run the following command to build docker image:
```bash
make build
make build-image
```

#### Run faucet
Run the following command to start the application:
Set the appropriate configuration in `.env` file and run the following command to start the application:

```bash
make docker-start WEB3_PROVIDER=<rpc-endpoint> PRIVATE_KEY=<hex-private-key>
make docker-start

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

or

```bash
make docker-start WEB3_PROVIDER=<rpc-endpoint> KEYSTORE=<keystore-path>
```

**NOTE**: Please replace `<rpc-endpoint>` and `<keystore-path>` with appropriate values.

## License

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/jellydator/ttlcache/v2 v2.11.1
github.com/kataras/hcaptcha v0.0.2
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/urfave/negroni v1.0.0
golang.org/x/crypto v0.22.0
)
Expand Down Expand Up @@ -68,6 +69,7 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand All @@ -92,5 +94,6 @@ require (
golang.org/x/time v0.5.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit af94b98

Please sign in to comment.