Skip to main content

Primer ecosystem toolkit for x402

Project description

primer-x402

PyPI version License

Primer ecosystem toolkit for x402. Built on the official x402 SDK.

This package extends the official x402 SDK with Primer-specific infrastructure: our facilitator, SKALE network support, and Prism ERC-20 settlement.

Installation

pip install primer-x402

This automatically installs x402 as a dependency.

Quick Start

Using Primer's Facilitator

from primer_x402 import primer_facilitator, primer_facilitator_sync

# Async client
facilitator = primer_facilitator()
result = await facilitator.verify(payload, requirements)

# Sync client
facilitator_sync = primer_facilitator_sync()
result = facilitator_sync.verify(payload, requirements)

SKALE Networks (Gas-Free)

from primer_x402 import skale_networks

# Use SKALE for gas-free transactions
network = skale_networks.base           # "eip155:1187947933"
network = skale_networks.base_sepolia   # "eip155:324705682"

Prism ERC-20 Settlement

For standard ERC-20 tokens (not USDC/EURC), use Prism:

from eth_account import Account
from web3 import Web3
from primer_x402 import create_prism_payload, PrismPaymentParams

web3 = Web3(Web3.HTTPProvider("https://mainnet.base.org"))
account = Account.from_key("0x...")

payload = create_prism_payload(
    account,
    web3,
    PrismPaymentParams(
        token="0x...",  # ERC-20 token address
        to="0x...",     # Recipient
        value=1000000,  # Amount in smallest unit
    ),
    "eip155:8453",
)

Note: Payers must first approve the Prism contract (0x402357ff1e18d42d0f14a5d56d6e1ebd741b3a86) to spend their tokens.

CLI

The package includes a CLI for scaffolding new x402 projects.

Create a Paid AI Proxy (Chutes)

Scaffold a FastAPI server that proxies Chutes (Bittensor Subnet 64) AI endpoints with x402 micropayments:

primer-x402 create chutes-proxy my-ai-api
cd my-ai-api
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows
pip install -r requirements.txt

Edit main.py to set your wallet address:

RECIPIENT = "0xYourWalletAddress"

Set your Chutes API key and run:

cp .env.example .env
# Edit .env with your CHUTES_API_KEY
export $(cat .env | xargs)
uvicorn main:app --reload

The generated proxy exposes these paid endpoints:

Endpoint Default Price
/v1/chat/completions $0.001
/v1/completions $0.001
/v1/embeddings $0.0001
/v1/images/generations $0.01

Payments are verified via Primer's facilitator and accepted on Base mainnet. Edit the generated code to customize pricing, networks, or add additional endpoints.

API Reference

Facilitator

Export Description
primer_facilitator() Async client for x402.primer.systems
primer_facilitator_sync() Sync client for x402.primer.systems
PRIMER_FACILITATOR_URL "https://x402.primer.systems"

Networks

Export Value
skale_networks.base "eip155:1187947933"
skale_networks.base_sepolia "eip155:324705682"
skale_rpc_urls.base "https://skale-base.skalenodes.com/v1/base"
skale_rpc_urls.base_sepolia "https://base-sepolia-testnet.skalenodes.com/v1/..."

Prism Settlement

Export Description
create_prism_payload(account, web3, params, network) Create signed ERC-20 payment
get_prism_nonce(web3, user, token) Get current nonce for user/token
PrismPaymentParams Dataclass for payment parameters
PrismPayload TypedDict for the resulting payload
PRISM_CONTRACT_ADDRESS "0x402357ff1e18d42d0f14a5d56d6e1ebd741b3a86"
PRISM_ABI Contract ABI (minimal)
ERC20_PAYMENT_TYPES EIP-712 type definitions

Supported Networks

Network Chain ID Facilitator
Base eip155:8453 ✓ Primer
Base Sepolia eip155:84532 ✓ Primer
SKALE Base eip155:1187947933 ✓ Primer
SKALE Base Sepolia eip155:324705682 ✓ Primer

Links

License

Apache-2.0 — Primer Systems

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

primer_x402-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

primer_x402-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file primer_x402-1.0.0.tar.gz.

File metadata

  • Download URL: primer_x402-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for primer_x402-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f61128b5abfb646e0445d8aa9db9079d12a160d72438305577c8156768b19b3a
MD5 44bdf87b117e55de78c4dc4f97f3fa90
BLAKE2b-256 c588b756300257000e77212dc4cdc0111396b60000134fe4f91cdb0c1582a96a

See more details on using hashes here.

File details

Details for the file primer_x402-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: primer_x402-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for primer_x402-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4c48f9befce36012bb40adcd7ac963899cddd9bf47fb0c3d9abe2da01913c24
MD5 9b833f4ccac97a9e2e98118620b793f7
BLAKE2b-256 942de6466d05d3fec0f641f8bdf1751a6be6a96791b97ee1edbd16c321d31d1f

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