Skip to content

Commit

Permalink
fix: configurations and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecarpini committed Aug 1, 2024
1 parent 774bae9 commit 7af573d
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 193 deletions.
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SHELL := /bin/bash

help:
@egrep -h '\s#@\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?#@ "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'

# Thor solo
solo-up: #@ Start Thor solo
docker compose -f packages/contracts/docker-compose.yaml up -d --wait thor-solo
solo-down: #@ Stop Thor solo
docker compose -f packages/contracts/docker-compose.yaml down
solo-clean: #@ Clean Thor solo
docker compose -f packages/contracts/docker-compose.yaml down -v --remove-orphans

# Database
DB_COMMAND=docker compose -f packages/database/docker-compose-mongo.yaml
DB_MAKE_KEY=mkdir -p packages/database/keys; openssl rand -base64 756 > packages/database/keys/keyfile;
DB_REMOVE_KEY=rm -f -R packages/database/keys
DB_SETUP_COMMAND=docker compose -f packages/database/docker-compose-mongo-setup.yaml

db-all: #@ Remove, clean and start all the database.
make db-down db-clean db-up db-setup
db-up: #@ Start the database.
$(DB_COMMAND) up -d --wait
db-clean: #@ Clean all the database data
$(DB_COMMAND) down -v --remove-orphans;
db-down: #@ Stop the database.
$(DB_COMMAND) down
db-keyfile-create: #@ Generate the keyfile for the database.
$(DB_MAKE_KEY)
db-keyfile-remove: #@ Remove the keyfile for the database.
$(DB_REMOVE_KEY)
db-setup: #@ Setup the database.
$(DB_SETUP_COMMAND) up --build; $(DB_SETUP_COMMAND) rm --force

NAV_CONTRACTS=cd packages/contracts

# Contracts
contracts-compile: #@ Compile the contracts.
$(NAV_CONTRACTS); yarn compile
contracts-deploy: contracts-compile solo-up #@ Deploy the contracts.
$(NAV_CONTRACTS); yarn deploy
contracts-test: contracts-compile #@ Test the contracts.
$(NAV_CONTRACTS); yarn test

# Apps
install: #@ Install the dependencies.
yarn install
build: install #@ Build the app.
yarn build
test: #@ Test the app.
yarn test
.PHONY:build
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# React Dapp Template 🚀

This is a simple template of a decentralized application (DApp) built with React, and Solidity. It is designed to help you kickstart your DApp development journey.

This template creates a simple DApp that allows users to interact with an erc20 token contract called *Fiorino*. Users can send and receive tokens, and the contract owner can mint new tokens.

## Requirements

Ensure your development environment is set up with the following:

- **Node.js (v18 or later):** [Download here](https://nodejs.org/en/download/package-manager) 📥
- **Yarn:** [Install here](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) 🧶
- **Docker (for containerization):** [Get Docker](https://docs.docker.com/get-docker/) 🐳
- **Hardhat (for smart contracts):** [Getting Started with Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started) ⛑️

## Project Structure

### Frontend (apps/frontend) 🌐

A blazing-fast React application powered by Vite:

- **Vechain dapp-kit:** Streamline wallet connections and interactions. [Learn more](https://docs.vechain.org/developer-resources/sdks-and-providers/dapp-kit)

### Contracts (packages/contracts) 📜

Smart contract in Solidity, managed with Hardhat for deployment on the Vechain Thor network.

### Packages 📦

Shared configurations and utility functions to unify and simplify your development process.

### Getting Started

Clone the repository and install dependencies with ease:

```bash
yarn # Run this at the root level of the project
```

Place your `.env` files in the root folder, you can copy `.env.example` file and rename it to `.env` changing the values to your own:

## Running on Solo Network Locally (docker needed!) 🔧

### Spin up the Solo Network in a docker container:

```bash
yarn solo-up
```

### Run the frontend and deploy the contracts on the Local Solo Network (if not deployed yet) with a single command:

```bash
yarn dev
```

You should see a log like this, that means the frontend is running:

```bash
frontend:dev: VITE v5.3.2 ready in 135 ms
frontend:dev:
frontend:dev: ➜ Local: http://localhost:5001/
frontend:dev: ➜ Network: http://192.168.1.26:5001/
frontend:dev: ➜ Network: http://192.168.64.1:5001/
frontend:dev: ➜ press h + enter to show help
```

and then you see a log like this, that means the contracts are deployed:

```bash
@repo/contracts:check-contracts-deployment: ================ Contracts deployed in 0m 9s
@repo/contracts:check-contracts-deployment: Contracts { fiorino: '0xE55842798426F155Ad7Ff6E9C93378690d1FF46a' }
@repo/contracts:check-contracts-deployment: Contracts and libraries addresses saved to /path/apps/react-dapp-template/packages/contracts/deploy_output
@repo/contracts:check-contracts-deployment: Total execution time: 0m 9s
@repo/contracts:check-contracts-deployment: Deployment completed successfully!
@repo/contracts:check-contracts-deployment: ================================================================================
@repo/contracts:check-contracts-deployment: Writing new config file to /path/apps/react-dapp-template/packages/config/local.ts
```
or a log like this, that means the contracts are already deployed (if you run the `yarn dev` command again):
```bash
@repo/contracts:check-contracts-deployment: Checking contracts deployment on vechain_solo (http://localhost:8669)...
@repo/contracts:check-contracts-deployment: fiorino contract already deployed
```
### Redeploy the contracts:
```bash
yarn contracts:deploy
```
or
Put empty string in the `fiorinoContractAddress` in the `packages/config/local.ts` file:
```typescript
fiorinoContractAddress: "",
```
and then run the `yarn dev` command again.
### Spin down the Solo Network
```bash
yarn solo-down
```
### Clean docker solo network
```bash
yarn solo-clean
```
## Running on Testnet 🌐
### Deploy the contracts on the Testnet:
```bash
yarn contracts:deploy:testnet
```
### Run the frontend to interact with the contracts on the Testnet:
```bash
yarn dev:testnet
```
## Running on Mainnet 🌐
### Deploy the contracts on the Mainnet:
```bash
yarn contracts:deploy:mainnet
```
### Run the frontend to interact with the contracts on the Mainnet:
```bash
yarn dev:mainnet
```
## Disclaimer ⚠️
This template serves as a foundational starting point and should be thoroughly reviewed and customized to suit your project’s specific requirements. Pay special attention to configurations, security settings, and environment variables to ensure a secure and efficient deployment.
2 changes: 2 additions & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"build": "tsc && vite build --mode=development",
"clean": "rm -rf dist .turbo",
"dev": "vite",
"dev:testnet": "vite",
"dev:mainnet": "vite",
"gh-pages-build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview --mode=development",
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
"purge": "turbo purge",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"dev": "yarn && dotenv -v VITE_APP_ENV=local -- turbo dev --",
"dev:staging": "yarn && dotenv -v VITE_APP_ENV=solo-staging -e .env -- turbo dev --",
"dev:testnet": "yarn && dotenv -v VITE_APP_ENV=testnet -e .env -- turbo dev:testnet --",
"dev:mainnet": "yarn && dotenv -v VITE_APP_ENV=mainnet -e .env -- turbo dev:mainnet --",
"contracts:compile": "dotenv -v VITE_APP_ENV=local -- turbo run compile --filter=@repo/contracts",
"contracts:deploy": "dotenv -v VITE_APP_ENV=local -- turbo run deploy --filter=@repo/contracts",
"contracts:deploy:solo-staging": "dotenv -v VITE_APP_ENV=solo-staging -- turbo run deploy --filter=@repo/contracts",
"contracts:deploy:testnet": "dotenv -v VITE_APP_ENV=testnet -- turbo run deploy:testnet --filter=@repo/contracts",
"contracts:deploy:mainnet": "dotenv -v VITE_APP_ENV=mainnet -- turbo run deploy:mainnet --filter=@repo/contracts",
"check-contracts-deployment": "npx hardhat run scripts/checkContractsDeployment.ts",
"check-contracts-deployment:testnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_testnet",
"check-contracts-deployment:mainnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_mainnet"
"check-contracts-deployment:mainnet": "npx hardhat run scripts/checkContractsDeployment.ts --network vechain_mainnet",
"solo-up": "make solo-up",
"solo-down": "make solo-down",
"solo-clean": "make solo-clean"
},
"devDependencies": {
"prettier": "^3.2.5",
Expand Down
9 changes: 0 additions & 9 deletions packages/config/contracts/envs/soloStaging.ts

This file was deleted.

11 changes: 1 addition & 10 deletions packages/config/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
export * from "./type";

import { createLocalConfig } from "./envs/local";
import { createSoloStagingConfig } from "./envs/soloStaging";
import { createE2EConfig } from "./envs/e2e";
import { createTestnetConfig } from "./envs/testnet";
import { createMainnetConfig } from "./envs/mainnet";

export const EnvConfigValues = [
"local",
"e2e",
"solo-staging",
"testnet",
"mainnet",
] as const;
export const EnvConfigValues = ["local", "e2e", "testnet", "mainnet"] as const;
export type EnvConfig = (typeof EnvConfigValues)[number];

export function getContractsConfig(env: EnvConfig) {
Expand All @@ -21,8 +14,6 @@ export function getContractsConfig(env: EnvConfig) {
return createLocalConfig();
case "e2e":
return createE2EConfig();
case "solo-staging":
return createSoloStagingConfig();
case "testnet":
return createTestnetConfig();
case "mainnet":
Expand Down
2 changes: 1 addition & 1 deletion packages/config/contracts/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type ContractsConfig = {
VITE_APP_ENV: "local" | "e2e" | "solo-staging" | "testnet" | "mainnet";
VITE_APP_ENV: "local" | "e2e" | "testnet" | "mainnet";
CONTRACTS_ADMIN_ADDRESS: string;
XAPP_BASE_URI: string;
};
2 changes: 0 additions & 2 deletions packages/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import localConfig from "./local";
import stagingConfig from "./solo-staging";
import testnetConfig from "./testnet";
import mainnetConfig from "./mainnet";
import { EnvConfig, getContractsConfig } from "./contracts";
Expand All @@ -21,7 +20,6 @@ export const getConfig = (env?: EnvConfig): AppConfig => {
);
if (appEnv === "local") return localConfig;
if (appEnv === "e2e") return localConfig;
if (appEnv === "solo-staging") return stagingConfig;
if (appEnv === "testnet") return testnetConfig;
if (appEnv === "mainnet") return mainnetConfig;
throw new Error(`Unsupported VITE_APP_ENV ${appEnv}`);
Expand Down
72 changes: 35 additions & 37 deletions packages/config/local.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
import { AppConfig } from ".";
const config: AppConfig = {
environment: "solo-staging",
basePath: "http://localhost:3000",
fiorinoContractAddress: "0x9e993Ac115BF2AC3Dee79f7652E2289c55c9C176",
nodeUrl: "http://localhost:8669",
network: {
id: "solo",
name: "solo",
type: "solo",
defaultNet: true,
urls: ["http://localhost:8669"],
explorerUrl: "https://explore-testnet.vechain.org",
blockTime: 10000,
genesis: {
number: 0,
id: "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6",
size: 170,
parentID:
"0xffffffff53616c757465202620526573706563742c20457468657265756d2100",
timestamp: 1530316800,
gasLimit: 10000000,
beneficiary: "0x0000000000000000000000000000000000000000",
gasUsed: 0,
totalScore: 0,
txsRoot:
"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",
txsFeatures: 0,
stateRoot:
"0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550",
receiptsRoot:
"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",
signer: "0x0000000000000000000000000000000000000000",
isTrunk: true,
transactions: [],
},
import { AppConfig } from "."
const config: AppConfig = {
"environment": "local",
"basePath": "http://localhost:3000",
"nodeUrl": "http://localhost:8669",
"network": {
"id": "solo",
"name": "solo",
"type": "solo",
"defaultNet": true,
"urls": [
"http://localhost:8669"
],
"explorerUrl": "https://explore-testnet.vechain.org",
"blockTime": 10000,
"genesis": {
"number": 0,
"id": "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6",
"size": 170,
"parentID": "0xffffffff53616c757465202620526573706563742c20457468657265756d2100",
"timestamp": 1530316800,
"gasLimit": 10000000,
"beneficiary": "0x0000000000000000000000000000000000000000",
"gasUsed": 0,
"totalScore": 0,
"txsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",
"txsFeatures": 0,
"stateRoot": "0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550",
"receiptsRoot": "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",
"signer": "0x0000000000000000000000000000000000000000",
"isTrunk": true,
"transactions": []
}
},
"fiorinoContractAddress": "0x5d4188A633E1E6F4c6a3846dEbaBaa730AF58e6A"
};
export default config;
export default config;
Loading

0 comments on commit 7af573d

Please sign in to comment.