The official Python SDK for the PayNode Protocol (v3.1). PayNode allows autonomous AI Agents to seamlessly pay for APIs and computational resources using USDC on Base L2, utilizing the standardized HTTP 402 protocol with support for both on-chain receipts and off-chain signatures (EIP-3009).
For complete installation guides, advanced usage, API references, and architecture details, please visit our official documentation: 👉 docs.paynode.dev
pip install paynode-sdk-python web3from paynode_sdk import PayNodeAgentClient
agent = PayNodeAgentClient(
private_key="YOUR_AGENT_PRIVATE_KEY",
rpc_urls=["https://mainnet.base.org", "https://rpc.ankr.com/base"]
)
# Automatically handles the 402 challenge, executes the Base L2 transaction, and gets the data.
response = agent.request_gate("https://api.merchant.com/premium-data", method="POST", json={"agent": "PythonAgent"})
print(response.json())- EIP-3009 Support: Sign payments off-chain using
TransferWithAuthorization, allowing for gasless or relayer-mediated settlement. - X402 V2 Protocol: JSON-based handshake for more structured and machine-readable payment instructions.
- Dual Flow: Automatic fallback to V1 (on-chain receipts) for legacy merchant support.
- FastAPI Middleware: Easy-to-use middleware for merchants to protect their API routes.
- TRON Support: USDT (TRC-20) payment integration.
- Solana Support: SPL USDC/USDT payment integration.
- Cross-chain: Universal settlement via bridges.
The SDK includes a complete Merchant/Agent demo in the examples/ directory.
Copy the example environment file and fill in your keys:
cp .env.example .env
# Edit .env with your private key and RPC URLsIf you're testing on Sepolia, run the helper script to mint 1,000 mock USDC:
python examples/mint_test_tokens.pypython examples/fastapi_server.pyIn another terminal:
python examples/agent_client.pyThe demo will perform a full loop: 402 Handshake -> On-chain Payment -> 200 Verification.
To publish a new version of the SDK:
- Install build tools:
pip install build twine
- Build the package:
python -m build
- Upload to PyPI:
python -m twine upload dist/*
Built for the Autonomous AI Economy by PayNodeLabs.