genlayer-project-boilerplate README

The project's README from github.com/genlayerlabs/genlayer-project-boilerplate. As one markdown file: README.md.

Sample GenLayer project

License: MIT Discord Telegram Twitter GitHub star chart

About

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

What's included

Requirements

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

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:

genvm-lint check contracts/football_bets.py

The linter catches:

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):

pytest tests/direct/ -v

Direct mode features used in these tests:

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 deploy the contract to GenLayer Studio and test with real consensus:

gltest tests/integration/ -v -s

These require GenLayer Studio running (local or hosted).

6. Set up the frontend

  1. Copy frontend/.env.example to frontend/.env
  2. Add your deployed contract address as NEXT_PUBLIC_CONTRACT_ADDRESS
  3. Run:
cd frontend
npm install
npm run dev

The app will be available at http://localhost:3000/.

How the Football Bets Contract Works

  1. Creating Bets: Users bet on a football match by providing the game date, teams, and predicted winner.
  2. Resolving Bets: After the match, the contract fetches results from BBC Sport, uses an LLM to extract the score, and validates via the equivalence principle.
  3. Points: Correct predictions earn points. Users can query their points or the leaderboard.

Testing Strategy

Test Type Command Speed Requires Studio
Lint genvm-lint check contracts/*.py ~250ms No
Direct pytest tests/direct/ -v ~ms/test No
Integration gltest tests/integration/ -v -s ~min/test Yes

Recommended workflow:

  1. Lint after every contract change
  2. Run direct tests frequently during development
  3. Run integration tests before deployment to verify consensus behavior

For AI coding agents (Claude Code, Cursor, etc.), the linter and direct tests provide the fast feedback loop needed for iterative development without requiring a running Studio instance.

Community

Documentation

For detailed information, see our documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

genlayer-project-boilerplate (genlayerlabs/genlayer-project-boilerplate)

Searching Database…

这是什么?这是一个用于构建 GenLayer 智能合约应用的样板项目,通过一个示例足球竞猜游戏进行演示:合约会获取真实的比赛结果,并使用大语言模型(LLM)来结算竞猜。
这是智能合约框架,还是现成的应用?这是一个全栈入门模板:包含基于 Python 的 GenLayer 智能合约,搭配 Next.js 15 TypeScript 前端,并提供测试和部署工具。
我该怎么把它跑起来?搭建 Python 环境,使用 GenVM 检查工具对合约进行检查,运行直连模式测试,通过 'genlayer deploy' 部署合约,然后运行集成测试,并复制 frontend/.env.example 文件、运行 npm 命令来配置前端。
开始之前需要先安装什么?你需要安装 Python 3.12+、通过 npm 全局安装的 GenLayer CLI,以及 GenLayer Studio(本地版或托管版),以便运行集成测试和部署。
没有 GenLayer Studio 能运行集成测试吗?不能。集成测试需要 GenLayer Studio 处于运行状态,可以是本地版或托管版;只有直连模式测试和代码检查无需它也能运行。
这个模板适合谁使用?面向开发 GenLayer 智能合约的开发者,尤其是使用 Claude Code 或 Cursor 等 AI 编程代理的人,他们需要通过代码检查和直连测试获得快速反馈。
示例足球竞猜合约到底是怎么运作的?用户下注预测比赛胜者;比赛结束后,合约从 BBC Sport 获取比赛结果,使用 LLM 提取比分,通过 GenLayer 的等价原则进行验证,并为预测正确的用户加分。
合约检查工具会检查哪些内容?它会检查被禁止的导入、等价原则代码块之外的非确定性调用、无效的存储类型(必须使用 TreeMap、DynArray、u256 等)、缺失的装饰器和返回类型注解,以及 20 多条其他规则。
直连模式测试和集成测试有什么区别?直连模式测试会在内存中运行合约,并模拟网页和 LLM 调用,几毫秒即可获得反馈,无需 Studio;集成测试则部署到 GenLayer Studio,验证真实的共识行为,每个测试需要数分钟。
是否包含 CI 流水线?包含。GitHub Actions 工作流会在 CI 流水线中自动运行代码检查和直连模式测试。
Size
1.1 MB
Stars
18.8K
Age
2y
Commits · 90 Days