The VoteChain Relay Server is a microservice designed to facilitate meta-transactions for the VoteChain system. It enables users to cast votes on the blockchain without directly paying gas fees. The relay server handles transaction signing, fee payment, and forwarding transactions to the blockchain seamlessly.
It also incorporates JWT-based authentication and session management using PostgreSQL via the Diesel ORM.
- Meta-transactions: Users sign transactions offline; the server pays gas fees and relays them.
- Blockchain Integration: Connects to an Ethereum-compatible blockchain using RPC.
- JWT Authentication: Secure API access with JSON Web Tokens.
- Session Management: Stores session data using PostgreSQL.
- RESTful API: Provides routes for managing polls and votes.
Follow these steps to set up and run the project locally.
Ensure you have the following installed:
- Rust (latest stable version)
- Docker & Docker Compose (for PostgreSQL)
- Node.js (optional, for interacting with MetaMask)
-
Clone the Repository
git clone https://github.com/your-repo/votechain-relay.git cd votechain-relay
-
Environment Configuration
Copy the example environment file and configure it.
cp .env.example .env
Remember to update
.env
with your settings (e.g., RPC URL, database credentials, JWT secrets, wallet private key). -
Start PostgreSQL Database
Use Docker Compose to run PostgreSQL locally:
docker-compose up -d
-
Install Dependencies
cargo build
-
Run Database Migrations
Apply database schema using Diesel.
diesel migration run
-
Run the Server
Start the Actix-Web server:
cargo run
The server will be available at the local address defined in
.env
(default:http://localhost:8080
).
Below is a quick overview of the API routes:
Method | Endpoint | Description |
---|---|---|
POST | /auth/signin |
Sign in a user and get JWT |
POST | /auth/refresh |
Refresh access token |
Method | Endpoint | Description |
---|---|---|
GET | /polls |
Retrieve all available polls |
GET | /polls/{id} |
Retrieve a specific poll |
POST | /polls/create |
Create a new poll on-chain |
POST | /polls/cast_vote |
Cast a vote in an active poll |
Method | Endpoint | Description |
---|---|---|
GET | /health |
Check server health |
This project leverages the following libraries and technologies:
-
Rust: Core programming language.
- Actix-Web: High-performance web framework for API development.
- Diesel: ORM for managing PostgreSQL database connections and migrations.
- jsonwebtoken: Library for handling JWT-based authentication.
- alloy-rs: For interacting with Ethereum-compatible blockchains (e.g., RPC, signing).
-
PostgreSQL: Relational database for storing session data.
The VoteChain Relay Server is a critical component of the VoteChain ecosystem, which provides a decentralized, blockchain-based voting platform. It ensures seamless interaction between users, the blockchain, and off-chain services. The ecosystem includes:
-
VoteChain Smart Contracts (
votechain
):- Written in Solidity, these contracts manage all on-chain voting logic, including poll creation, vote casting, and result aggregation.
- Designed to be immutable and transparent, ensuring trust in the voting process.
-
VoteChain Relay Server (this project):
- Facilitates meta-transactions to offload gas fees from users by relaying signed transactions to the blockchain.
- Manages secure authentication using JWT tokens and session data stored in a PostgreSQL database.
- Acts as a bridge between the blockchain and the client application, providing a user-friendly API.
-
VoteChain Client Application (
votechain-client
):- A front-end application for end-users to interact with the VoteChain system.
- Allows users to create polls, cast votes, and view results, utilizing wallets like MetaMask for signing transactions.
- Connects to the relay server to submit signed transactions and fetch poll data.
Together, these components form a secure, gas-optimized, and user-friendly voting solution, leveraging blockchain technology for transparency and decentralization.