> For the complete documentation index, see [llms.txt](https://docs.peach.ag/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.peach.ag/documentation/arc/aggregator/core-features/direct-allowance.md).

# Direct Swaps

Get a Direct quote and transaction with one swap call, then submit the accepted result.

The same account supplies input tokens and submits the swap. Call `arc.swapAllowance(params)` once to receive the quote and a validated `PreparedDirectSwap` with `status: "TRANSACTION_READY"`.

`executor` is required; `payer` and `recipient` default to executor. The payer must equal executor; recipient may differ. Set recipient, routing, fees, slippage and deadline in this one request.

### Get and submit a Direct result

These complete helpers use Arc Testnet and viem. `directSwap()` only gets terms. Display `prepared.expectAmountOut`, `prepared.tx.amountOutMin`, recipient and fees, and let the user accept them before calling `submitDirectSwap()` with that same result. Bind the confirmation to the order and discard it if any input changes.

```typescript
import { type Address, type PublicClient, type WalletClient } from "viem";
import { ArcClient, ARC_TESTNET_CONFIG, arcTestnet, type PreparedDirectSwap, type PreparedDelegatedSwap } from "@masterpeach/arc-aggregator-sdk";

/** Get the quote and transaction together; no approval, signature or submission. */
export async function directSwap(
  publicClient: PublicClient, wallet: WalletClient,
  from: Address, target: Address, amount: bigint,
) {
  const account = wallet.account ?? (await wallet.getAddresses())[0];
  if (!account) throw new Error("Connect a wallet account first");
  if (await wallet.getChainId() !== ARC_TESTNET_CONFIG.chainId) throw new Error("Switch to Arc Testnet");
  const executor = typeof account === "string" ? account : account.address;
  const arc = new ArcClient(ARC_TESTNET_CONFIG, publicClient);
const prepared = await arc.swapAllowance({ from, target, amount, executor, slippageBps: 50, deadlineSecs: 120 });
  if (prepared.amountIn !== amount) throw new Error("Prepared input differs from the order");
  return prepared;
}

/** Call after the user accepts this prepared result; reuse it without another swap request. */
export async function submitDirectSwap(
  publicClient: PublicClient, wallet: WalletClient, prepared: PreparedDirectSwap,
) {
  const account = wallet.account ?? (await wallet.getAddresses())[0];
  if (!account) throw new Error("Connect a wallet account first");
  const executor = typeof account === "string" ? account : account.address;
  if (executor.toLowerCase() !== prepared.executor.toLowerCase()) throw new Error("Wallet account changed");
  if (await wallet.getChainId() !== ARC_TESTNET_CONFIG.chainId) throw new Error("Switch to Arc Testnet");
  const arc = new ArcClient(ARC_TESTNET_CONFIG, publicClient);
  const approval = await arc.buildDirectApprovalRequest(prepared, executor);
  if (approval) {
    const hash = await wallet.sendTransaction({ ...approval.tx, account, chain: arcTestnet });
    const receipt = await publicClient.waitForTransactionReceipt({ hash });
    if (receipt.status !== "success") throw new Error(`Approval reverted: ${hash}`);
  }
  if (prepared.execution.plan.deadline <= BigInt(Math.floor(Date.now() / 1_000))) {
    throw new Error("Swap expired; get and confirm a new result");
  }
  await publicClient.call({ ...prepared.tx, account: executor });
  const hash = await wallet.sendTransaction({ ...prepared.tx, account, chain: arcTestnet });
  console.log("Transaction hash:", hash); // Save before waiting; resolve uncertain outcomes before retrying.
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
  if (receipt.status !== "success") throw new Error(`Swap reverted: ${hash}`);
  return { hash, receipt };
}
```

The helper preserves bound LocalAccounts and browser wallet addresses. It rechecks the wallet account and chain before approval. `buildDirectApprovalRequest()` uses the exact input amount by default; `{ approval: "max" }` requests unlimited allowance and should be disclosed. It returns `undefined` when allowance is sufficient. Some tokens require zeroing a nonzero allowance before approving a new value; the application must handle that token behavior.

### Result and execution

`swapAllowance()` returns quote amounts, roles, tokens, IDs, `approvalSpender`, validated `tx`, decoded `execution`, constraints and raw API data. `tx.amountOutMin` is the signed net minimum, and `execution.plan.deadline` is the signed expiry. Preserve the entire result unchanged.

Simulation uses the accepted transaction and current RPC state after approval. Only a successful receipt completes the trade. An expired plan requires a new result and new confirmation, not modified calldata or a higher tolerance. Resolve an uncertain submission before retrying.

See [Quickstart](https://docs.peach.ag/documentation/arc/aggregator/quickstart), [Slippage](https://docs.peach.ag/documentation/arc/aggregator/core-features/slippage), and [Transaction Safety](https://docs.peach.ag/documentation/arc/aggregator/core-features/validation-approvals-and-expiry).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.peach.ag/documentation/arc/aggregator/core-features/direct-allowance.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
