x402 payment contract template library for GenLayer — Paywall, Metered, Subscription, Escrow
Project description
genlayer-x402
x402 Payment Protocol for GenLayer Intelligent Contracts
A library of 4 production-ready Intelligent Contracts that bring the HTTP 402 Payment Required standard onto the GenLayer blockchain. Gate real-time web data and AI services behind trustless, on-chain payments — without any server, API key, or middleman.
What is this?
Traditional paid APIs rely on centralized servers with API keys — fragile, censorable, and opaque. genlayer-x402 moves the payment gate fully on-chain:
- Trustless verification — payment checked by GenLayer validators, not a central server
- Real-time web data — contracts fetch live data via
gl.nondet.web.get()after payment clears - AI-powered judgment — the escrow contract uses LLM consensus to auto-approve/reject deliverables
- Revenue withdrawal — owners can withdraw accumulated revenue to their wallet anytime
- Immutable access — once a user pays, price changes never revoke their access
- Anti-lockup safeguards — escrow has arbiter + timeout mechanisms to prevent stuck funds
Prerequisites
- Python 3.12+ — Download
- Node.js 18+ — Download
- Docker 26+ — Download (only if running local Studio)
- A funded GenLayer account — Get test GEN from the testnet faucet
Installation
pip install genlayer-x402
Also install the linter and GenLayer CLI:
pip install genvm-linter
npm install -g genlayer
Getting the Contract Files
GenLayer contracts run as single Python files, so you need to copy them into your project before deploying.
Recommended (CLI)
After installing the package, run:
genlayer-x402 init
This will create a contracts/ folder with all contracts:
contracts/ ├── x402_paywall.py ├── x402_metered.py ├── x402_subscription.py ├── x402_escrow.py
Copy a single contract
genlayer-x402 paywall
genlayer-x402 metered
genlayer-x402 subscription
genlayer-x402 escrow
List available contracts
genlayer-x402 list
🧰 CLI Usage
| Command | Description |
|---|---|
genlayer-x402 init |
Copy all contracts |
genlayer-x402 paywall |
Copy paywall contract |
genlayer-x402 metered |
Copy metered contract |
genlayer-x402 subscription |
Copy subscription contract |
genlayer-x402 escrow |
Copy escrow contract |
genlayer-x402 list |
Show available contracts |
Testing Guides
Each contract has a detailed step-by-step testing guide in the docs/ folder:
| Contract | Guide | Est. Time |
|---|---|---|
| Overview + Setup | docs/TESTING.md | 5 min |
| X402Paywall | docs/test-paywall.md | ~20 min |
| X402Metered | docs/test-metered.md | ~25 min |
| X402Subscription | docs/test-subscription.md | ~30 min |
| X402Escrow | docs/test-escrow.md | ~40 min |
Contributing
Issues and pull requests welcome!
- Fork the repo
- Create a feature branch
- Commit changes with clear messages
- Open a Pull Request
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genlayer_x402-0.2.2.tar.gz.
File metadata
- Download URL: genlayer_x402-0.2.2.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
776e7728080c1fa30db9b5e1760fba45f2cd8a5f3a575302c89a281e8287dd09
|
|
| MD5 |
aa3ac9fcb441ab65c16aba9642766a3f
|
|
| BLAKE2b-256 |
03505506a4abe2ec75b45a751eb8ea5c594a9cbb45947945bb7f5592e61fc7d8
|
File details
Details for the file genlayer_x402-0.2.2-py3-none-any.whl.
File metadata
- Download URL: genlayer_x402-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0642c6c4eb6ce8b8925a188034115e020683f71323e98de266ab88f6a01683d4
|
|
| MD5 |
862c69f5691497f9e80a7efae2ddf8a8
|
|
| BLAKE2b-256 |
71fd8265f6aa5c3e4d59c49ba008018f6523b01475c1a59abcd7262376103e7b
|