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, Robinhood Chain 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"

Robinhood Chain

from primer_x402 import robinhood_networks

# Use Robinhood Chain
network = robinhood_networks.mainnet    # "eip155:4663"
network = robinhood_networks.testnet    # "eip155:46630"

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/..."
robinhood_networks.mainnet "eip155:4663"
robinhood_networks.testnet "eip155:46630"
robinhood_rpc_urls.mainnet "https://rpc.mainnet.chain.robinhood.com"
robinhood_rpc_urls.testnet "https://rpc.testnet.chain.robinhood.com"

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
Robinhood Chain eip155:4663 ✓ Primer
Robinhood Chain Testnet eip155:46630 ✓ 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.1.0.tar.gz (13.7 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.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: primer_x402-1.1.0.tar.gz
  • Upload date:
  • Size: 13.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 4aecdd55d65b7f73b38dd40ac33ee30aa0556bd82889721f407c78c952f0bafc
MD5 ab4384e8655fd0e89ddb60a364c6b707
BLAKE2b-256 ffb4b98c6563cafc02599de5cec571d261044aaadb3d9cab4d27e213d6b6603e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: primer_x402-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6dfe4e0fce842de689ed1f31b325f14d52ae18d244ae9f5b0d3ff6e3423b27
MD5 c68abf32c032783e96c354f074f565db
BLAKE2b-256 3223f4342ebe83e6e6a140236cec6c078287eb45d1a2cd78f026a717d2a14779

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