Skip to main content

x402 payment contract template library for GenLayer — Paywall, Metered, Subscription, Escrow

Project description

genlayer-x402

x402 Payment Protocol for GenLayer Intelligent Contracts

License: MIT GenLayer x402 PyPI

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


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!

  1. Fork the repo
  2. Create a feature branch
  3. Commit changes with clear messages
  4. Open a Pull Request

License

MIT — see LICENSE.

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.2.2.tar.gz (15.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.2.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

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

Hashes for genlayer_x402-0.2.2.tar.gz
Algorithm Hash digest
SHA256 776e7728080c1fa30db9b5e1760fba45f2cd8a5f3a575302c89a281e8287dd09
MD5 aa3ac9fcb441ab65c16aba9642766a3f
BLAKE2b-256 03505506a4abe2ec75b45a751eb8ea5c594a9cbb45947945bb7f5592e61fc7d8

See more details on using hashes here.

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

Hashes for genlayer_x402-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0642c6c4eb6ce8b8925a188034115e020683f71323e98de266ab88f6a01683d4
MD5 862c69f5691497f9e80a7efae2ddf8a8
BLAKE2b-256 71fd8265f6aa5c3e4d59c49ba008018f6523b01475c1a59abcd7262376103e7b

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