Import
Signature
Helper to execute full payment flow for an x402 payment challenge. Automates the complete client payment workflow:
  1. Fetches current suggested transaction parameters from the algod client.
  2. Matches the requirement against the active algod network using selectRequirement.
  3. Builds the exact AVM atomic transaction group via buildExactAvmGroup.
  4. Calls signTxns for the transaction indexes requiring payer signature.
  5. Assembles signed and unsigned transactions and encodes the PAYMENT-SIGNATURE header.

Parameters

PaymentRequired
required
The PaymentRequired challenge from HTTP 402 response.
string
required
Algorand address of the paying account.
algosdk.Algodv2
required
Algodv2 client instance for the active network.
(txns: Uint8Array[], indexes: number[]) => Promise<(Uint8Array | null)[]>, controls: SpendControls = {}
required
Callback function that signs unsigned transaction byte arrays for specified indexes.

Returns

Promise<string>
Promise resolving to the base64-encoded PAYMENT-SIGNATURE header string.

Throws

  • NoSupportedRequirementError: If accepts is empty.
  • NetworkMismatchError: If no offer is for the algod’s network.
  • SpendLimitExceededError: If the amount is above the cap.
  • PaymentNotAllowedError: If the asset, network or recipient is not allowed. Errors from algod or from signTxns propagate unchanged.

Example

Source: src/index.ts