Skip to main content

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 genlayer runtime
  • Import may fail outside GenLayer environment (this is expected)

📜 License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genlayer_x402-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genlayer_x402-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for genlayer_x402-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75af05b59d0481bd932c31fec17ffb0574df1acc2852c1a7f6b1ef023442e865
MD5 db5ca540483ff604afe3d691b41c4ced
BLAKE2b-256 1898180c842910646b3c024ecadb65cd94f42580f4f4f28b12bd9d553d7a2309

See more details on using hashes here.

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

Hashes for genlayer_x402-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c746d5f43aba61e325b339dd6c2f4af6f9ba9b9f80b268585d5ddcd90f91be80
MD5 88d2f0b2db201b6f761180025b08dec2
BLAKE2b-256 58979afef81a1dc4ccdc6955adbdcf35d6987063857a4b7975480c0e09f976f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page