Decentralized Applications
Project Boilerplate

GenLayer Project Boilerplate

The GenLayer Project Boilerplate is a template for building decentralized applications (DApps) on GenLayer. This boilerplate includes a complete example implementation of a football prediction market, demonstrating best practices and common patterns for GenLayer development.

This boilerplate is a work in progress and is not yet ready for production use. You can find the latest version at: GenLayer Project Boilerplate (opens in a new tab)

Features

  • Contract Templates: Ready-to-use intelligent contract templates and examples
  • Testing Framework: Built-in testing infrastructure for end-to-end testing
  • Frontend Integration: Vue.js-based frontend setup with GenLayerJS integration
  • Environment Configuration: Pre-configured environment setup for development
  • Example Implementation: Full football prediction market implementation

How it's Built

The boilerplate project is structured to provide a development environment for GenLayer applications, combining both backend contract development and frontend user interface.

Technologies Used

  • Python: For intelligent contract development and testing
  • Vue.js: Frontend framework for building user interfaces
  • GenLayerJS: SDK for interacting with GenLayer contracts
  • pytest: Testing framework for contract validation
  • Vite: Frontend build tool and development server

Project Structure

project-root/
β”œβ”€β”€ app/                 # Frontend application
β”‚   β”œβ”€β”€ src/             # Vue.js source files
β”‚   └── .env.example     # Frontend environment variables template
β”œβ”€β”€ contracts/           # Intelligent contracts
β”‚   └── football_prediction_market.py
β”œβ”€β”€ test/                # Test files
└── .env.example         # Main environment variables template

Requirements

Before using the GenLayer Project Boilerplate, ensure your system meets the following requirements:

  • GenLayer Studio: Running instance required
  • Node.js: Version 18.x or higher
  • Python: Version 3.8 or higher

Installation

  1. Clone the boilerplate repository:
git clone https://github.com/yeagerai/genlayer-project-boilerplate
cd genlayer-project-boilerplate
  1. Set up the environment:
cp .env.example .env

Usage

Deploying Contracts

  1. Access the GenLayer Simulator UI (default: http://localhost:8080 (opens in a new tab))
  2. Navigate to "Contracts" section
  3. Create a new contract using /contracts/football_prediction_market.py
  4. Deploy through the "Run and Debug" interface

Frontend Setup

  1. Configure the frontend environment:
cd app
cp .env.example .env
# Add your contract address to VITE_CONTRACT_ADDRESS
  1. Install dependencies and start the development server:
npm install
npm run dev

Running Tests

Execute the test suite using pytest:

pip install -r requirements.txt
pytest test

Football Prediction Market Example

The included example contract demonstrates a complete prediction market implementation with the following features:

Contract Functions

Create Predictions:

create_prediction(game_date: str, team1: str, team2: str, predicted_winner: str)

Resolve Predictions:

resolve_prediction(prediction_id: str)

Query Data:

get_player_predictions(player_address: str)
get_player_points(player_address: str)

Frontend Integration

The Vue.js frontend demonstrates:

  • Wallet connection handling
  • Contract interaction using GenLayerJS
  • User interface for prediction creation and management
  • Real-time updates for prediction status

Testing Framework

The boilerplate includes a comprehensive testing suite covering the following scenarios:

Contract Schema

The schema of the contract is well generated and has the expected methods and variables.

Test Scenarios

Successful Draw Prediction

Tests the scenario where a player correctly predicts a draw between two teams. When the match is resolved as a draw, the player should receive 1 point for their accurate prediction.

Successful Winner Prediction

Validates the case where a player correctly predicts the winning team. Upon match resolution confirming their predicted team as the winner, the player should be awarded 1 point.

Unsuccessful Prediction

Covers the scenario where a player's prediction doesn't match the actual result. This could be:

  • Predicting Team A wins, but Team B wins
  • Predicting a draw, but there's a winner
  • Predicting a winner, but the match ends in a draw In all these cases, the player should receive 0 points.

Best Practices

  • Always use environment variables for configuration
  • Implement comprehensive testing for all contract functions
  • Follow the provided folder structure for consistency
  • Use TypeScript for frontend development
  • Implement proper error handling in both contract and frontend code