# x402-avm-js reference

> Every export of x402-avm-js, generated from the TSDoc in src/index.ts and src/errors.ts.

`x402-avm-js` has 32 exports, all named exports of the package root ([`x402-avm-js` on npm](https://www.npmjs.com/package/x402-avm-js)). It is an ES module with one runtime dependency, `algosdk`.

```ts
import { payForRequirement, decodePaymentRequired, SpendLimitExceededError } from 'x402-avm-js';
```

## Payments

| Export | Kind | Summary |
|---|---|---|
| [`payForRequirement`](https://x402-avm.github.io/reference/js/pay-for-requirement) | function | Helper to execute full payment flow for an x402 payment challenge. |
| [`decodePaymentRequired`](https://x402-avm.github.io/reference/js/decode-payment-required) | function | Decode a base64-encoded PAYMENT-REQUIRED header value into a PaymentRequired object. |
| [`parsePaymentRequired`](https://x402-avm.github.io/reference/js/parse-payment-required) | function | Validate untrusted input (for example a decoded PAYMENT-REQUIRED header) and return it as a {@link PaymentRequired}. |
| [`selectRequirement`](https://x402-avm.github.io/reference/js/select-requirement) | function | Select the first acceptable payment requirement matching the payer's network. |
| [`buildExactAvmGroup`](https://x402-avm.github.io/reference/js/build-exact-avm-group) | function | Build atomic transaction group for Exact AVM payment scheme. |
| [`encodePaymentHeader`](https://x402-avm.github.io/reference/js/encode-payment-header) | function | Encode a payment payload into a base64-encoded PAYMENT-SIGNATURE header. |

## Spend controls

| Export | Kind | Summary |
|---|---|---|
| [`checkSpendControls`](https://x402-avm.github.io/reference/js/check-spend-controls) | function | Check a requirement against spend controls. |
| [`SpendControls`](https://x402-avm.github.io/reference/js/spend-controls) | interface | Client-side limits checked before anything is signed. |
| [`AmountLimit`](https://x402-avm.github.io/reference/js/amount-limit) | type | A limit in base units: bigint, a non-negative safe integer, a decimal string, or `Infinity` for no cap. |
| [`DEFAULT_MAX_AMOUNT`](https://x402-avm.github.io/reference/js/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`](https://x402-avm.github.io/reference/js/build-identity-txn) | function | Build an identity transaction for wallet ownership proof. |
| [`encodeIdentityHeader`](https://x402-avm.github.io/reference/js/encode-identity-header) | function | Encode signed identity transaction bytes to base64 string for the X-Identity-Txn header. |

## Networks

| Export | Kind | Summary |
|---|---|---|
| [`resolveNetwork`](https://x402-avm.github.io/reference/js/resolve-network) | function | Resolve a network name, alias, or legacy ID into a canonical CAIP-2 identifier. |
| [`networkFromGenesisHash`](https://x402-avm.github.io/reference/js/network-from-genesis-hash) | function | Derive the canonical CAIP-2 identifier from a network's genesis hash per the Algorand profile. |
| [`networkFromAlgod`](https://x402-avm.github.io/reference/js/network-from-algod) | function | Query an algod client for its current suggested transaction parameters and return its CAIP-2 identifier. |
| [`algodClient`](https://x402-avm.github.io/reference/js/algod-client) | function | Create an Algodv2 client for a named network or custom endpoint. |
| [`MAINNET`](https://x402-avm.github.io/reference/js/mainnet) | constant | MainNet network constants and public AlgoNode endpoints. |
| [`TESTNET`](https://x402-avm.github.io/reference/js/testnet) | constant | TestNet network constants and public AlgoNode endpoints. |
| [`LOCALNET_ENDPOINTS`](https://x402-avm.github.io/reference/js/localnet-endpoints) | constant | LocalNet endpoints and token. |

## Types

| Export | Kind | Summary |
|---|---|---|
| [`PaymentRequired`](https://x402-avm.github.io/reference/js/payment-required) | interface | Decoded payload of the HTTP 402 PAYMENT-REQUIRED header. |
| [`PaymentRequirements`](https://x402-avm.github.io/reference/js/payment-requirements) | interface | Payment requirements specified by an x402 server. |
| [`ResourceInfo`](https://x402-avm.github.io/reference/js/resource-info) | interface | Metadata about the protected resource in an x402 payment challenge. |
| [`BuildGroupResult`](https://x402-avm.github.io/reference/js/build-group-result) | interface | Result of building an atomic transaction group for the exact AVM payment scheme. |
| [`AlgorandNetwork`](https://x402-avm.github.io/reference/js/algorand-network) | interface | Network configuration and endpoints for an Algorand network. |

## Errors

| Export | Kind | Summary |
|---|---|---|
| [`X402AvmError`](https://x402-avm.github.io/reference/js/x402-avm-error) | class | Typed errors thrown by x402-avm-js. |
| [`SpendLimitExceededError`](https://x402-avm.github.io/reference/js/spend-limit-exceeded-error) | class | The requested amount is above the client's spend cap. |
| [`PaymentNotAllowedError`](https://x402-avm.github.io/reference/js/payment-not-allowed-error) | class | The requirement's asset, network or recipient is not on the caller's allow list. |
| [`InvalidPaymentRequiredError`](https://x402-avm.github.io/reference/js/invalid-payment-required-error) | class | The PAYMENT-REQUIRED header or object is malformed, or a requirement in it is not a valid exact-AVM offer. |
| [`NoSupportedRequirementError`](https://x402-avm.github.io/reference/js/no-supported-requirement-error) | class | The challenge offers nothing this client can pay (`accepts` is empty). |
| [`NetworkMismatchError`](https://x402-avm.github.io/reference/js/network-mismatch-error) | class | None of the offered requirements is for the network the wallet is on, or a requirement's genesis does not match. |
| [`UnknownNetworkError`](https://x402-avm.github.io/reference/js/unknown-network-error) | class | A network name or CAIP-2 identifier is not recognised, or has no default endpoint. |
| [`InvalidOptionsError`](https://x402-avm.github.io/reference/js/invalid-options-error) | class | A spend-control option is malformed (for example a negative or non-integer maxAmount). |

Source: https://x402-avm.github.io/reference/js/index
