x402 contract library for GenLayer
Project description
genlayer-x402
x402 Payment Protocol for GenLayer Intelligent Contracts
A reusable library of 4 Intelligent Contracts implementing the HTTP 402 Payment Required standard on GenLayer.
This package provides ready-to-use contract patterns for building paid APIs, AI services, and on-chain payment flows — without centralized servers.
🚀 What is this?
genlayer-x402 is a contract library, not a standalone app.
It gives you reusable building blocks for:
- Pay-per-access APIs
- Credit-based billing
- Subscription systems
- Escrow with AI verification
All logic runs on-chain via GenLayer, not locally.
📦 Contracts Included
| Contract | Description |
|---|---|
X402Paywall |
One-time payment → permanent access |
X402Metered |
Credit-based pay-per-call |
X402Subscription |
Usage quota per period |
X402Escrow |
AI-verified escrow with safety |
📥 Installation
Install from GitHub
pip install git+https://github.com/habiiyt31/genlayer-x402.git
🧠 Usage (inside GenLayer contract)
import genlayer as gl
from genlayer_x402 import X402Paywall
class MyApp(gl.Contract):
def __init__(self):
self.paywall = X402Paywall(
price_wei=1000000000000000000,
data_url="https://api.example.com"
)
⚠️ Note: This library is intended to run inside GenLayer contracts, not as a local Python runtime.
⚙️ Deployment
Deploy contracts using GenLayer CLI:
genlayer deploy --contract contracts/x402_paywall.py
Follow prompts to input constructor arguments.
💰 GEN & Wei
GenLayer uses:
1 GEN = 10^18 wei
Example:
| GEN | Wei |
|---|---|
| 1 GEN | 1000000000000000000 |
| 0.1 GEN | 100000000000000000 |
🔐 Features
- On-chain payment verification
- Real-time web data (
gl.nondet.web.get) - AI-assisted validation (Escrow)
- Revenue withdrawal (
withdraw,withdraw_all) - Permanent access after payment (Paywall)
- Anti-lock escrow mechanisms
📁 Project Structure
genlayer-x402/
│
├── genlayer_x402/ # Library package
│ ├── __init__.py
│ ├── x402_paywall.py
│ ├── x402_metered.py
│ ├── x402_subscription.py
│ └── x402_escrow.py
│
├── docs/ # Testing guides
├── README.md
├── LICENSE
🧪 Testing
See documentation in:
docs/
Each contract has its own test guide.
⚠️ Important Notes
- This is not a local Python library
- Contracts depend on
genlayerruntime - Import may fail outside GenLayer environment (this is expected)
📜 License
MIT
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.1.0.tar.gz.
File metadata
- Download URL: genlayer_x402-0.1.0.tar.gz
- Upload date:
- Size: 10.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 |
75af05b59d0481bd932c31fec17ffb0574df1acc2852c1a7f6b1ef023442e865
|
|
| MD5 |
db5ca540483ff604afe3d691b41c4ced
|
|
| BLAKE2b-256 |
1898180c842910646b3c024ecadb65cd94f42580f4f4f28b12bd9d553d7a2309
|
File details
Details for the file genlayer_x402-0.1.0-py3-none-any.whl.
File metadata
- Download URL: genlayer_x402-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 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 |
c746d5f43aba61e325b339dd6c2f4af6f9ba9b9f80b268585d5ddcd90f91be80
|
|
| MD5 |
88d2f0b2db201b6f761180025b08dec2
|
|
| BLAKE2b-256 |
58979afef81a1dc4ccdc6955adbdcf35d6987063857a4b7975480c0e09f976f7
|