# Quickstart

### Install <a href="#install" id="install"></a>

```bash
npm install @peachprojects/aggregator-sdk ethers
```

Requires Node.js >= 18 and ethers v6.

### Initialize <a href="#initialize" id="initialize"></a>

{% code fullWidth="false" %}

```ts
import { PeachClient, BSC_MAINNET_CONFIG } from "@peachprojects/aggregator-sdk";
import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://bsc-dataseed.binance.org");

const client = new PeachClient(BSC_MAINNET_CONFIG, provider, {
  api: {
    baseUrl: "https://api.peach.ag",
  },
});
```

{% endcode %}

`getQuote()` requires `options.api`. If you already have route data from the API, you can also build a quote locally with `buildQuoteFromRouteData()`.

### Get a Quote <a href="#get-a-quote" id="get-a-quote"></a>

```ts
const quote = await client.getQuote({
  srcToken: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", // WBNB
  dstToken: "0x55d398326f99059fF775485246999027B3197955", // USDT
  amountIn: ethers.parseEther("1"),
});
```

All seven DEX providers are queried by default. To restrict routing:

```ts
const quote = await client.getQuote({
  srcToken,
  dstToken,
  amountIn,
  options: {
    providers: ["PANCAKEV3", "UNISWAPV3"],
    deadlineSeconds: 1200,                    // optional — default 20 minutes
    customFee: {                              // optional — integrator (custom) fee
      feeAccount: "0xYourIntegratorWallet",   // optional - custom fee will transfer to feeAccount directly
      feeBps: 100,                            // optional - 1% — capped at MAX_FEE_BPS (500 bps = 5%)
    },
  },
});
```

### Prepare and Send the Swap <a href="#prepare-and-send-the-swap" id="prepare-and-send-the-swap"></a>

```ts
const signer = new ethers.Wallet(PRIVATE_KEY, provider);
const owner = await signer.getAddress();

const prepared = await client.swap(quote, owner, { slippageBps: 50 });

// Step 1: Approve if needed (ERC20 input only; native BNB skips this)
if (prepared.approval) {
  const approvalTx = await signer.sendTransaction(prepared.approval.tx);
  await approvalTx.wait();
}

// Step 2: Execute the swap
const swapTx = await signer.sendTransaction(prepared.tx);
await swapTx.wait();
```

`swap()` returns transaction requests — it does not broadcast. You control when and how to send.

### Optional: Simulate Before Sending <a href="#optional-simulate-before-sending" id="optional-simulate-before-sending"></a>

```ts
const { amountOut, method } = await client.simulate(quote, 50);
console.log("Simulated output:", amountOut.toString());
```

Simulation runs an `eth_call` with no gas cost or state change, useful for verifying the quote before committing.

### Direct API <a href="#direct-api" id="direct-api"></a>

If you prefer not to use the SDK, call the routing API directly:

BaseUrl: <https://api.peach.ag>

| Endpoint                  | Purpose                               |
| ------------------------- | ------------------------------------- |
| `GET /router/find_routes` | Route discovery and quote             |
| `GET /router/status`      | Provider availability and sync status |


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.peach.ag/documentation/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
