# decodePaymentRequired

> Decode a base64-encoded PAYMENT-REQUIRED header value into a PaymentRequired object.

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

```ts
export function decodePaymentRequired(headerB64: string): PaymentRequired;
```

Decode a base64-encoded PAYMENT-REQUIRED header value into a PaymentRequired object.

Parses the base64-encoded JSON payload received in an HTTP 402 response into a typed
PaymentRequired structure without relying on Node.js binary APIs.

## Parameters

- `headerB64` (`string`, required):
Base64-encoded string from the PAYMENT-REQUIRED response header.

## Returns

- `returns` (`PaymentRequired`):
Decoded PaymentRequired object.

## Throws

- `InvalidPaymentRequiredError`: If decoding or JSON parsing fails, or the decoded shape is invalid.

## Example

```ts
const header = response.headers.get('PAYMENT-REQUIRED');
const challenge = decodePaymentRequired(header);
console.log(challenge.x402Version); // 2
```

Source: [src/index.ts](https://github.com/x402-avm/x402-avm-js/blob/main/src/index.ts#L389)

Source: https://x402-avm.github.io/reference/js/decode-payment-required
