Skip to content

Commit

Permalink
Gsoc 2024 Remerge (#67)
Browse files Browse the repository at this point in the history
* Fixed errors & optimized vote button

* Created main.yml

* Update Workflow

* testing workflow

* updated node v20

* Updated publish_branch

* Removed workflow changes

* Documentation Changes

* Chatbot with Next

* Added chatbot changes

* reducing intents

* optimized chatbot file

* Vercel.json file added

* -

* chanin maxLambdasize

* added cpu pytorch

* version change

* changed to flask-cpu

* changed version

* new chatbot deploy

* reduced intents

* changes for railway

* removing serverless

* Created main.yml

* Update Workflow

* testing workflow

* updated node v20

* Updated publish_branch

* Removed workflow changes

* reduced intents

* changes for railway

* removing serverless

* Delete HashIPFS.ts

* Update page.tsx

* edited docs

---------

Co-authored-by: Ronnieraj37 <[email protected]>
Co-authored-by: Raj Ranjan <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent 0a3ff79 commit 54e1f3c
Show file tree
Hide file tree
Showing 49 changed files with 545 additions and 1,316 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added .gitlab/.DS_Store
Binary file not shown.
359 changes: 0 additions & 359 deletions DOCUMENTATION.md

This file was deleted.

192 changes: 98 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,143 +1,147 @@
# Agora Blockchain

# Agora Blockchain

## Prerequisites (only for contributing)
## Introduction

- Basic familarity with [Git](https://git-scm.com/), [NodeJS](https://nodejs.org/en) and [npm](https://www.npmjs.com/).
- Basic familarity with [ReactJS](https://reactjs.org/), [React context APIs](https://reactjs.org/docs/context.html), if working on frontend part.
- Basic familarity with Blockchain, [Solidity](https://docs.soliditylang.org/en/v0.8.6/) and [Hardhat](https://hardhat.org/), if working on blockchain part.
Agora is a library of voting algorithms like `Moore's`, `Oklahoma` , `Borda` , `IRV` etc. Some of these voting algorithms are already implemented by AOSSIE in a centralized manner using Scala as their backend. Our vision is to take these algorithms on a decentralized platform, so that, crucial votes of the voters could not be tampered with by admins, hackers, or anyone with access to the database. Blockchain technology would make the ballots immutable and hence more secure.

## Requirements
## Tech Stack

- [NodeJS](https://nodejs.org/en) >= 10.16 and [npm](https://www.npmjs.com/) >= 5.6 installed.
- [Git](https://git-scm.com/) installed in the system.
- [Hardhat](https://hardhat.org/), which can be installed globally with `npm install --save-dev hardhat`
- [Metamask](https://metamask.io) extension added to the browser.
- ### Backend

## Development Guide
- [Solidity](https://docs.soliditylang.org/en/v0.8.24/): A programming language used for developing smart contracts on the Ethereum ecosystem.
- [Hardhat](https://hardhat.org/): A development environment for testing, deploying, and managing smart contracts.
- [ChainLink](https://docs.chain.link/ccip): Facilitates cross-chain interoperability within the ecosystem.
- [EIPs](https://eips.ethereum.org/): Utilized for implementing the latest Ethereum Improvement Proposals.
- [OpenZeppelin](https://www.openzeppelin.com/): Provides a collection of well-audited, secure smart contracts that are easy to integrate and use.

**Clone the repository**

```bash
git clone https://gitlab.com/aossie/agora-blockchain/
```

**Switch to develop branch**

```bash
git checkout develop
```
- ### Client

The frontend code is inside the `client` directory, whereas the smart contracts (solidity) is present inside `server` folder. You may proceed to `client` folder if you are here for enhancing frontend part of the Agora Blockchain. Else you can proceed to `server` folder for enhancing the efficiency or introducing new features in the blockchain part of the Agora.
- [Next.js](https://nextjs.org/): A React framework used for developing the frontend of the application.
- [Node.js](https://nodejs.org/en/) (v10.16 or later): A JavaScript runtime required for server-side development.
- [MetaMask](https://metamask.io): A browser extension for managing Ethereum accounts and interacting with the blockchain.
- [Vercel](https://vercel.com/) - The platform used for deploying the Next.js frontend, offering seamless deployment and hosting with serverless functions.
- [Wagmi](https://wagmi.sh/): A set of React hooks for working with Ethereum contracts.
- [TailwindCSS](https://tailwindcss.com/): A utility-first CSS framework for efficient styling.
- [zustand](https://zustand.docs.pmnd.rs/getting-started/introduction): A state management library for React, used for managing global state in the Next.js application.

> Whatever dependencies you need for frontend should be saved in their local `package.json` and not in the global one. This would ensure that a developer who only want to contribute to blockchain code, should not install unneccessary frontend dependencies and vice-versa.
Here's a refined version of the development guide:

## Setting up client side
## Development Guide

Frontend code is present inside the `client` folder. Thus, the dependencies required for frontend are listed in the local `package.json` of `client` folder. You can install only the client-side dependencies using the following command.
### Running Locally

**Install client-side dependencies**
**Clone the Repository**:

```bash
npm run install-client --force
git clone https://github.com/AOSSIE-Org/Agora-Blockchain
```

or
## Backend

```bash
cd client
npm install
```
1. **Navigate to the Blockchain Directory**:

**Start frontend**
```bash
cd blockchain
```

For development purpose we will run this command to start our client react app.
2. **Install Dependencies**:

```bash
npm run client
```
```bash
npm install
```

or
3. **Test the Contracts**:

```bash
cd client
npm start
```
```bash
npx hardhat test
```

**Build production for client**
4. **Create an `.env.local` file** with the following environment variables:

> Only required while deploying frontend to some hosting services like AWS, Heroku, GCP etc.
```bash
PRIVATE_KEY=<your_private_key>
RPC_URL_SEPOLIA=<your_sepolia_rpc_url>
RPC_URL_FUJI=<your_fuji_rpc_url>
ETHERSCAN_KEY=<your_etherscan_api_key>
```

This will create production build folder inside the `client` directory with the minified code of frontend. The production build will be served using `server.js` file inside the `client` folder.
5. **Compile & Deploy Contracts**:
```bash
npx hardhat ignition deploy ./ignition/modules/<ContractModule> --network <Network> --verify
```

```
npm run build
```
## Frontend

Deploying the repository to **Heroku** would automatically serve production build of the client side. This is because, **Heroku** uses `npm run build` for deploying our application. Once the `build` is complete, it uses the `npm start` command. In the `package.json` file of root directory, you can see `node client/server.js` command against `start` script. This will serve the minified files from `build` direcotry.
1. **Navigate to the Client Directory**:

## Setting up Hardhat
```bash
cd client
```

Smart contracts or blockchain codes and necessary config files for developing, testing and deploying them are present inside `server` directory. Inside the `server` folder, there is `contracts` directory which stores **Agora Blockchain**'s business logic i.e. the smart contracts. `migrations` folder contains files for migrating smart contracts to the blockchain network. Go through these smart contracts and start contributing.
2. **Install Dependencies**:

**About smart contracts**
```bash
npm install
```

We use Hardhat for editing, compiling, debugging and deploying your smart contracts and dApps, all of which work together to create a complete development environment. Compiled smart contracts or build files are then stored inside the `/artifacts/contracts` directory. You need to copy the required files to the frontend after compiling.
3. **Run the Application**:

**Install server-side dependencies**
```bash
npm run dev
```

```bash
npm run install-server
```
4. **Create an `.env.local` file** with the following environment variables:

or
```bash
NEXT_PUBLIC_PINATA_JWT=<your_pinata_jwt>
```

```bash
cd server
npm install
```
5. **Visit the Live App at**:
**[localhost](http://localhost:3000/)**

> Now move inside `server` folder for the next steps.
## About smart contracts

**Compiling smart contracts**
The architecture of your Election Factory contract is designed to facilitate the creation and management of elections on the blockchain, incorporating cross-chain voting capabilities through Chainlink's Cross-Chain Interoperability Protocol (CCIP). Below is a detailed explanation:

If we have altered the code within our Solidity files (.sol) or made new ones or just want generate build files for the client, we need to run `npx hardhat compile` in the terminal. Compiled files are generated inside `/artifacts/contracts/File_name/`.
### Overview

```bash
npx hardhat compile
```
The `ElectionFactory` contract serves as the core component of the election creation and management system. It is responsible for generating new election instances, handling cross-chain voting, and maintaining a record of active elections. The contract leverages several other contracts and libraries to achieve its functionality, including the `Election`, `BallotGenerator`, and `ResultCalculator` contracts, as well as Chainlink's CCIP components.

**Create a .env file**
- ### Key Features:

For deploying smart contracts on a blockchain network we need two things: A node connected to the network through which we will make RPC calls and an account with few coins, to cover the cost of deployment. [Infura](https://infura.io/) provides us the node for Ethereum network. So register there and put the Infura's API key inside of the `.env` file, like shown below.
- Election Creation: Utilizes a clonable election template (electionGenerator) to efficiently create new election contracts.
- Ballot and Result Handling: Generates ballots using the BallotGenerator contract and calculates election results with a dedicated ResultCalculator contract.
- Cross-Chain Voting: Implements Chainlink's Cross-Chain Interoperability Protocol (CCIP) to allow voting from multiple blockchain networks.

```bash
MNEMONIC="<YOUR_SEED_GOES_HERE>"
KEY="<YOUR INFURA KEY GOES HERE>"
```
- ### Efficiency and Security:

Also save your wallet's mnemonic phrase against the MNEMONIC in .env file, and don't forget to fund the account corresponding to that mnemonic. There are several faucets available to fund your account with test tokens.
- Clonable Contracts: Reduces deployment costs and resource usage by cloning a pre-deployed election template.
- Owner Management: Ensures only the election creator can delete or modify their election, providing security and control.
- Whitelisted Cross-Chain Communication: Only allows approved contracts to send votes across chains, preventing unauthorized access.

> Never share or commit your `.env` file. It contains your credentials like `mnemonics` and `API` key. Therefore, it is advised to add `.env` to your `.gitignore` file.
## Deployed Instances

**Deploying smart contracts**
- **Election Factory**: [Sepolia Testnet](https://sepolia.etherscan.io/address/0x64c720eBD5227bba57a5E8282893e71087cCcBb8#code)
- **CCIP Contract**: [FUJI Testnet](https://testnet.snowtrace.io//address/0xf267f0603672E791779E52B153BD9A39C9928767#code)
- **Frontend**: [Live URL](https://agora-blockchain.vercel.app/)

You can deploy the smart contracts in the localhost network following these steps:
## How to Contribute

- Start a local node

```bash
npx hardhat node
```

- Open a new terminal and deploy the smart contract in the localhost network.


```bash
npx hardhat run --network localhost scripts/deploy.js
```
1. **Create an Issue**: For any feature requests, bugs, security concerns, or other issues, please create an issue in the repository and wait to be assigned before proceeding.
2. **Branch Management**: Always create a new branch on your forked repository to commit your changes.
3. **Pull Request Descriptions**: When submitting a pull request (PR), provide a detailed explanation in the description, outlining all changes and the reasons behind them.
4. **Community Engagement**: Post your issues and PR updates on the Agora-Blockchain [Discord channel](https://discord.gg/HrJ6eKJ28a) for visibility and discussion.

The above line will print the contract addresses which are deployed, mentioned in `deploy.js`.
## Additional Points to Remember

Replace the contract addresses printed in the terminal with the contract addresses hard coded in the frontend files.
1. **Testing and Code Quality**: Ensure all changes are thoroughly tested, and avoid introducing code smells.
2. **Small Changes**: If a frontend change involves fewer than 20 lines of code or if you are making documentation updates, you may directly create a PR without prior assignment.
3. **Assignment Requirement**: Do not submit unassigned PRs; they will be closed without review.
4. **Avoiding Overlap**: Before starting work, check existing issues and PRs to avoid duplicating efforts or conflicting changes.
5. **Open Review Period**: A new issue or PR will remain open for one week to allow other contributors to review and suggest improvements.
6. **Mentor Notification**: If your PR is left unattended for more than 1-2 weeks, depending on the contribution size, feel free to tag the mentors of Agora-Blockchain to get their attention.
7. **Completion Timeline**: An issue is expected to be completed within 5-30 days, depending on its complexity. If not completed within this timeframe, it may be reassigned to another contributor.
8. **Progress Updates**: If your work on an issue is taking longer than expected, ensure you provide regular updates in the issue’s or PR's comments to keep everyone informed.
9. **Working on Blockchain Components**:
- **Error Interface Changes**: If modifying an interface for errors, ensure the corresponding error is added to `client/app/helper/ErrorMessage.ts`.
- **Contract ABI Updates**: For changes to `ElectionFactory`, `Election`, or `CCIPSender` contracts, manually update the ABI files in `client/abi/artifacts/` (do not configure Hardhat to generate these paths automatically in the client directory).
Binary file added anonymousVoting/.DS_Store
Binary file not shown.
Binary file added blockchain/.DS_Store
Binary file not shown.
Binary file added chatbot/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions chatbot/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python app.py
24 changes: 19 additions & 5 deletions chatbot/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
## Installation

### Create an environment using venv

```console
$ cd chat-bot
$ cd chatbot
$ python3 -m venv venv
```

### Activate it

Mac / Linux:

```console
. venv/bin/activate
```

Windows:

```console
venv\Scripts\activate
```

### Install PyTorch and dependencies

For Installation of PyTorch see [official website](https://pytorch.org/).

You also need `nltk`:
```console

```console
pip install nltk flask_cors numpy torch flask
```
```

If you get an error during the first run, you also need to install `nltk.tokenize.punkt`:
Run this once in your terminal:
```console

```console
$ python
>>> import nltk
>>> nltk.download('punkt')
>>> nltk.download('punkt_tab')
```

## Usage

Run

```console
python train.py
```

This will dump `data.pth` file. And then run

```console
python app.py
```

## Customize

Have a look at [intents.json](intents.json). You can customize it according to your own use case. Just define a new `tag`, possible `patterns`, and possible `responses` for the chat bot. You have to re-run the training whenever this file is modified.

```console
{
"intents": [
Expand Down
Loading

0 comments on commit 54e1f3c

Please sign in to comment.