x402-avm-js has 32 exports, all named exports of the package root (x402-avm-js on npm). It is an ES module with one runtime dependency, algosdk.
import { payForRequirement, decodePaymentRequired, SpendLimitExceededError } from 'x402-avm-js';
Payments
| Export | Kind | Summary |
|---|---|---|
payForRequirement | function | Helper to execute full payment flow for an x402 payment challenge. |
decodePaymentRequired | function | Decode a base64-encoded PAYMENT-REQUIRED header value into a PaymentRequired object. |
parsePaymentRequired | function | Validate untrusted input (for example a decoded PAYMENT-REQUIRED header) and return it as a {@link PaymentRequired}. |
selectRequirement | function | Select the first acceptable payment requirement matching the payer’s network. |
buildExactAvmGroup | function | Build atomic transaction group for Exact AVM payment scheme. |
encodePaymentHeader | function | Encode a payment payload into a base64-encoded PAYMENT-SIGNATURE header. |
Spend controls
| Export | Kind | Summary |
|---|---|---|
checkSpendControls | function | Check a requirement against spend controls. |
SpendControls | interface | Client-side limits checked before anything is signed. |
AmountLimit | type | A limit in base units: bigint, a non-negative safe integer, a decimal string, or Infinity for no cap. |
DEFAULT_MAX_AMOUNT | constant | Default per-payment cap in base units (1 ALGO, or 1 USDC) applied when maxAmount is not set. |
Identity
| Export | Kind | Summary |
|---|---|---|
buildIdentityTxn | function | Build an identity transaction for wallet ownership proof. |
encodeIdentityHeader | function | Encode signed identity transaction bytes to base64 string for the X-Identity-Txn header. |
Networks
| Export | Kind | Summary |
|---|---|---|
resolveNetwork | function | Resolve a network name, alias, or legacy ID into a canonical CAIP-2 identifier. |
networkFromGenesisHash | function | Derive the canonical CAIP-2 identifier from a network’s genesis hash per the Algorand profile. |
networkFromAlgod | function | Query an algod client for its current suggested transaction parameters and return its CAIP-2 identifier. |
algodClient | function | Create an Algodv2 client for a named network or custom endpoint. |
MAINNET | constant | MainNet network constants and public AlgoNode endpoints. |
TESTNET | constant | TestNet network constants and public AlgoNode endpoints. |
LOCALNET_ENDPOINTS | constant | LocalNet endpoints and token. |
Types
| Export | Kind | Summary |
|---|---|---|
PaymentRequired | interface | Decoded payload of the HTTP 402 PAYMENT-REQUIRED header. |
PaymentRequirements | interface | Payment requirements specified by an x402 server. |
ResourceInfo | interface | Metadata about the protected resource in an x402 payment challenge. |
BuildGroupResult | interface | Result of building an atomic transaction group for the exact AVM payment scheme. |
AlgorandNetwork | interface | Network configuration and endpoints for an Algorand network. |
Errors
| Export | Kind | Summary |
|---|---|---|
X402AvmError | class | Typed errors thrown by x402-avm-js. |
SpendLimitExceededError | class | The requested amount is above the client’s spend cap. |
PaymentNotAllowedError | class | The requirement’s asset, network or recipient is not on the caller’s allow list. |
InvalidPaymentRequiredError | class | The PAYMENT-REQUIRED header or object is malformed, or a requirement in it is not a valid exact-AVM offer. |
NoSupportedRequirementError | class | The challenge offers nothing this client can pay (accepts is empty). |
NetworkMismatchError | class | None of the offered requirements is for the network the wallet is on, or a requirement’s genesis does not match. |
UnknownNetworkError | class | A network name or CAIP-2 identifier is not recognised, or has no default endpoint. |
InvalidOptionsError | class | A spend-control option is malformed (for example a negative or non-integer maxAmount). |