genlayerlabs /genlayer-project-boilerplate

★ 19,331⑂ 937
TypeScriptCreated 2024-06-28
19,331
stars
+37+49+955
937
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

Sample GenLayer project






 About
This project includes the boilerplate code for a GenLayer use case implementation, specifically a football bets game.

 What's included
- An example intelligent contract (Football Bets) with web access and LLM integration
- Direct mode tests — fast, in-memory unit tests with web/LLM mocking (~ms per test)
- Integration tests — full end-to-end tests against GenLayer Studio
- Contract linting — static analysis to catch common contract issues before deployment
- CI pipeline — GitHub Actions workflow for linting and direct tests
- A production-ready Next.js 15 frontend with TypeScript, TanStack Query, and Radix UI
- Configuration file template and deployment scripts

 Requirements
- Python = 3.12
- GenLayer CLI globally installed: npm install -g genlayer
- GenLayer Studio (for integration tests and deployment): Install from Docs or use the hosted GenLayer Studio

 Project Structure


contracts/               Python intelligent contracts
tests/
  direct/                Fast in-memory tests (no Studio required)
    test_create_bet.py    Bet creation logic
    test_resolve_bet.py   Bet resolution with web/LLM mocks
    test_views.py         Read-only view methods
  integration/            Full tests against GenLayer Studio
    test_football_bets.py
    fixtures.py           Expected state fixtures
frontend/                Next.js 15 app (TypeScript, TanStack Query, Radix UI)
deploy/                  TypeScript deployment scripts
gltest.config.yaml       Test runner network configuration
pyproject.toml           Python/pytest configuration
.github/workflows/       CI pipeline


 Quick Start

 1. Set up Python environment

shell
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt


 2. Lint your contracts

Run the GenVM linter to catch issues before deployment:

shell
genvm-lint check contracts/football_bets.py


The linter catches:
- Forbidden imports and non-deterministic calls
- Invalid storage types (must use TreeMap, DynArray, u256, etc.)
- Missing decorators and return type annotations
- Non-deterministic operations outside equivalence principle blocks
- And 20+ other rules

 3. Run direct mode tests

Direct mode tests run contracts in-memory without needing GenLayer Studio. They use mocks for web requests and LLM calls, giving you fast feedback (~milliseconds per test):

shell
pytest tests/direct/ -v


Direct mode features used in these tests:
- direct_deploy("contracts/file.py") — deploy contract in memory
- direct_vm.sender = address — set transaction sender
- direct_vm.mock_web(pattern, response) — mock HTTP/render calls
- direct_vm.mock_llm(pattern, response) — mock LLM responses
- direct_vm.expect_revert("message") — assert expected failures
- direct_vm.clear_mocks() — reset mocks between calls

 4. Deploy the contract

1. Choose your network: genlayer network
2. Deploy: genlayer deploy (runs the script in /deploy/deployScript.ts)

 5. Run integration tests

Integration tests dep

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON