Google AP2 × Algorand adapter — settle x402 payments from AP2 CartMandate/PaymentMandate
Project description
ap2-algorand
Google AP2 × Algorand x402 adapter — settle AI agent payments on Algorand from an AP2 PaymentMandate.
Bridges the Google Agent Payments Protocol (AP2) with non-custodial USDC payments on Algorand, enforced by AVM MandateContracts.
Install
pip install ap2-algorand
Quick start
Buyer: advertise x402 Algorand in a CartMandate
from ap2_algorand import AlgorandUsdcMethodData, X402_METHOD_NAME
from ap2.types.payment_request import PaymentMethodData
method = PaymentMethodData(
supported_methods=X402_METHOD_NAME, # "https://www.x402.org/"
data=AlgorandUsdcMethodData(
mandate_app_id=3_498_113_854, # agent's MandateContract app ID
asset_id=31_566_704, # mainnet USDC ASA
network="mainnet",
x402_endpoint="https://api.example.com/weather",
).model_dump(),
)
Buyer: parse payment args from a CartMandate
from ap2_algorand import cart_to_payment_args
args = cart_to_payment_args(cart_mandate)
# args.mandate_app_id → int
# args.amount_micro_usdc → int (e.g. 10_000 for $0.01 USDC)
# args.asset_id → int
# args.x402_endpoint → str
Merchant: submit payment and get a PaymentReceipt
import os
from ap2_algorand import settle
receipt = settle(
payment_mandate=payment_mandate,
algod_url="https://mainnet-api.algonode.cloud",
)
txid = receipt.payment_status.network_confirmation_id
# txid == Algorand transaction ID (network IS the ledger)
Lower-level: submit without AP2 types
from ap2_algorand import settle_raw
txid = settle_raw(
x_payment="<base64-msgpack-signed-tx>",
algod_url="https://mainnet-api.algonode.cloud",
)
How it maps to AP2
| AP2 field | Algorand value |
|---|---|
payment_response.method_name |
https://www.x402.org/ |
payment_response.details["value"] |
base64(msgpack(SignedTransaction)) |
merchant_confirmation_id |
Algorand txid |
psp_confirmation_id |
Algorand txid (AVM is the PSP) |
network_confirmation_id |
Algorand txid (Algorand is the network) |
| OTP challenge | skipped — AVM MandateContract enforces limits |
Dependencies
py-algorand-sdk >= 2.0pydantic >= 2.0ap2— optional, only needed forsettle()return type (PaymentReceipt)
License
MIT © Algo Wallet
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ap2_algorand-0.1.0.tar.gz.
File metadata
- Download URL: ap2_algorand-0.1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c490f3ed04f77cd3803454dda962db5df8750ef5db12349da635053be52ea906
|
|
| MD5 |
00db4070532e3694161497f19c7b2280
|
|
| BLAKE2b-256 |
71ab46e1dfafb9faae5edb11028ba22b4ff83d3228ff2a32651ce19de6049229
|
File details
Details for the file ap2_algorand-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ap2_algorand-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a90d56129263f3b20291038fe9764ae1104aac80511b8fa1445bd9f015856d1
|
|
| MD5 |
f9c4a9621730371396c71afc18b63ee4
|
|
| BLAKE2b-256 |
a49a2e005178f344dc26851ec013bd90426faf7ba9737922e2dfca9196bbd07c
|