# buildExactAvmGroup

> Build atomic transaction group for Exact AVM payment scheme.

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

```ts
export function buildExactAvmGroup(
  req: PaymentRequirements,
  payerAddress: string,
  suggestedParams: algosdk.SuggestedParams,
  controls: SpendControls = {}
): BuildGroupResult;
```

Build atomic transaction group for Exact AVM payment scheme.

If `extra.feePayer` is present in the requirement:
Creates a two-transaction atomic group:
1. Transaction [0]: Fee payer self-payment of 0 ALGO with pooled flat fee equal to `2 * minFee` (2,000 microALGO).
2. Transaction [1]: Payer transfer of `amount` with flat fee of 0.
Sets `paymentIndex = 1` and `signIndexes = [1]`.

If `extra.feePayer` is absent:
Creates a single transaction where the payer pays the standard fee:
Sets `paymentIndex = 0` and `signIndexes = [0]`.

Handles both native ALGO (asset ID "0") and Algorand Standard Assets (ASAs).

## Parameters

- `req` (`PaymentRequirements`, required):
Accepted payment requirement from the server.

- `payerAddress` (`string`, required):
Algorand address of the buyer/payer.

- `suggestedParams` (`algosdk.SuggestedParams`, required):
Current suggested transaction parameters from algod.

- `controls` (`SpendControls = {}`, required):
Spend controls checked before anything is built. Without `maxAmount`, amounts above {@link DEFAULT_MAX_AMOUNT} (1,000,000 base units) are refused.

## Returns

- `returns` (`BuildGroupResult`):
Object containing the transaction group, payment transaction index, and indexes requiring signature.

## Throws

- `SpendLimitExceededError`: If the amount is above the cap.
- `PaymentNotAllowedError`: If the asset, network or recipient is not allowed.
- `NetworkMismatchError`: If `extra.genesisHash` or `extra.genesisId` disagrees with `suggestedParams`.
- `InvalidPaymentRequiredError`: If the amount, asset, payTo or feePayer is malformed.

## Example

```ts
const sp = await algod.getTransactionParams().do();
const { txns, paymentIndex, signIndexes } = buildExactAvmGroup(
  requirement,
  activeAddress,
  sp
);
```

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

Source: https://x402-avm.github.io/reference/js/build-exact-avm-group
