Skip to main content

x402-algorand

Algorand (AVM) exact payment scheme plugin for the official x402 Python SDK.

Import name: x402_algorand. This package ships the Algorand mechanism as a modular plugin that integrates directly with the official x402 package on PyPI.

Installation

pip install x402-algorand

Installing x402-algorand automatically pulls the official x402 package.

Quickstart

Register the Algorand exact payment scheme with the official x402Client, x402ResourceServer, and x402Facilitator:

from x402 import x402Client, x402ResourceServer, x402Facilitator
from x402_algorand.exact.register import (
    register_exact_avm_client,
    register_exact_avm_server,
    register_exact_avm_facilitator,
)

# 1. Client setup
client = x402Client()
register_exact_avm_client(client, client_signer)

# 2. Server setup
server = x402ResourceServer(facilitator_client)
register_exact_avm_server(server)

# 3. Facilitator setup
facilitator = x402Facilitator()
register_exact_avm_facilitator(facilitator, facilitator_signer, networks="algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k")

Network Identifiers (CAIP-2)

In accordance with the Algorand CAIP-2 profile, network references use the first 32 characters of the URL-safe base64 encoding of the 32-byte genesis hash:

Network Genesis Hash (full base64) CAIP-2 Identifier
MainNet wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8= algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k
TestNet SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI= algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDe
CAIP-2 spec example mFgazF+2uRS1tMiL9dsj01hJGySEmPN28B/TjjvpVW0= algorand:mFgazF-2uRS1tMiL9dsj01hJGySEmPN2
LocalNet (default) tg0cyjEz14FZK9BTpL2q0TOyFbc0McwYsFJbszmFANk= algorand:tg0cyjEz14FZK9BTpL2q0TOyFbc0McwY

Custom networks can be registered dynamically via register_network(genesis_hash).

Spend controls

The official x402Client applies spend controls by default to prevent unintentional or excessive payments. ExactAvmScheme integrates directly with these controls via find_default_asset.

Default Allowances and Limits

By default, without custom configuration:

  • Allowed Assets:
    • ALGO (asset: "0"): Allowed on all valid Algorand networks (MainNet, TestNet, LocalNet, custom).
    • USDC: Allowed on MainNet (asset: "31566704") and TestNet (asset: "10458941").
  • Default Cap:
    • Payments are capped at $1 (DEFAULT_MAX_AMOUNT_PER_PAYMENT), corresponding to 1,000,000 base atomic units (6 decimals):
      • 1 ALGO (1,000,000 microAlgos)
      • 1 USDC (1,000,000 atomic units)
  • Any payment requesting an unknown asset or an amount exceeding 1,000,000 base units is rejected with NoMatchingRequirementsError.

Allowing Other ASAs and Custom Caps

You can whitelist additional ASAs, adjust per-asset caps, raise global USD caps, or disable spend controls using client.set_spend_controls(...) or x402Client.from_config(...):

# 1. Allow a custom ASA with an atomic spending cap:
client.set_spend_controls({
    "allowed_assets": [
        {
            "network": "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k",
            "asset": "12345678",  # ASA ID
            "max_amount_per_payment": "5000000",  # Base atomic units
        }
    ]
})

# 2. Raise the default USD cap for recognized assets (e.g. up to $10 per payment):
client.set_spend_controls({
    "max_amount_per_payment": "$10"
})

# 3. Allow any asset without asset-filtering restrictions:
client.set_spend_controls({
    "allowed_assets": True
})

# 4. Disable all spend controls entirely:
client.set_spend_controls(False)

Note that x402Client.__init__() takes only payment_requirements_selector. Spend controls are configured on the client via client.set_spend_controls(...) or when instantiating via x402Client.from_config(x402ClientConfig(spend_controls=...)).

Migration from 0.1.x

In version 0.1.x, x402-algorand replaced the entire x402 package and used from x402.mechanisms.avm.... In version 0.2.0:

  • Use from x402_algorand import ... instead of from x402.mechanisms.avm import ....
  • Core x402 classes (x402Client, x402ResourceServer, x402Facilitator) are imported directly from x402.
  • Network identifiers follow the 32-character CAIP-2 profile. Legacy 44-character IDs (algorand:<hash>=) remain accepted and are automatically converted.

License

Apache License 2.0. See LICENSE and NOTICE for details.

Metadata

Release files for x402-algorand 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for x402-algorand 0.2.0
File Size Uploaded Provenance Actions
x402_algorand-0.2.0.tar.gz 35.2 kB Without provenance Details for x402_algorand-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for x402-algorand 0.2.0
File Interpreter ABI Platform Actions
x402_algorand-0.2.0-py3-none-any.whl Python 3 none any Details for x402_algorand-0.2.0-py3-none-any.whl

Total release size: 72.5 kB

Release files / x402_algorand-0.2.0.tar.gz

Download URL x402_algorand-0.2.0.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e6a8a34e2b846915263b93ecb9e2cc9d4603593714aec42de40a906a839a8d81
BLAKE2b-256 checksum
How to use checksums
345b024968dbc85514e9c82c37bcbd732823fc6097cda29a3455cce433afaf14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / x402_algorand-0.2.0-py3-none-any.whl

Download URL x402_algorand-0.2.0-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b6b22760feb9e62a951be23f2152260807311bd110390365f097b4279503ef2
BLAKE2b-256 checksum
How to use checksums
7b7a7a7f1e6886f9c9bb8ec7f15f741aa061640ad3579f2f1f202bc612a7f3f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for x402-algorand 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page