For the complete documentation index, see llms.txt. This page is also available as Markdown.

Overview

How BSC Aggregator finds routes and prepares swaps for the Execution Router.

Use @masterpeach/aggregator-sdk@latest with ethers v6 to integrate BSC swaps. The Peach API finds routes across supported liquidity and builds transactions for the Peach Execution Router. All quotes and swaps are exact input.

Latest npm release: 0.5.0 (latest).

How it works

Use the method that matches who supplies the tokens and who submits the transaction:

Method
Use it for
Result

swapAllowance(params)

The same account supplies tokens and submits the swap

PreparedDirectSwap: quoted amounts, selected paths and an executable transaction

swapPermit2(params)

A payer authorizes a different executor to submit the swap

PreparedDelegatedSwap: quoted amounts, a frozen plan and payer signing material

swapPermit2Build(prepared, payerSignature)

Build the transaction after the payer signs the Permit2 authorization

ReadyDelegatedSwap: the final executable transaction for the prepared plan

Allowance gets the quote and transaction in one Aggregator request. Review the returned terms, approve tokens if needed and submit the same result with executeSwap().

Permit2 uses two Aggregator requests: swapPermit2() prepares the plan, and swapPermit2Build() returns the transaction after payer signing. Signing authorizes execution by the designated executor. See Delegated Swaps for the signing and build stages.

The service builds to, data and value and signs the execution plan. The SDK validates the response; the executor's signer then signs and submits the transaction through executeSwap(). Preparation and build do not broadcast. Token approvals, payer signing, optional simulation and waiting for the transaction receipt are separate actions.

Get started

Start with Quickstart for a complete example. Browse Core Features for topic guides, or SDK Reference for methods and types.

Execution flows

The payer supplies input tokens, the executor submits the swap and pays its gas, and the recipient receives the output. Allowance uses the same payer and executor; Permit2 requires different accounts and an explicit recipient. Approval details are in Direct Swaps and Delegated Swaps.

Installation and network

Use Node.js 18+ or a modern browser with an ethers-compatible provider. The package supplies ESM, CommonJS and TypeScript declarations.

Use BSC_MAINNET_CONFIG for BSC Mainnet (chain ID 56). Amounts are integer base units (bigint); use each token's decimals with ethers.parseUnits() and ethers.formatUnits(). See Contract Address for addresses and Native BNB for the native-token sentinel.

Production API

The SDK defaults to https://api.peach.ag. Use a BSC Mainnet RPC and wallet signer (chain ID 56).

The SDK validates router addresses from the execution response. See Client Configuration to pin them to verified addresses.

Production execution compatibility has not yet been verified for this documentation. Confirm support for the current execution workflow before enabling trading.

Continue with Quickstart or the SDK Reference.

Migrating an existing integration

The methods above include route discovery and quoting, so an existing getQuote() or find_routes prerequisite can be removed. find_routes remains available for compatibility and is planned for future deprecation; no removal date is announced.

Follow Migration Guide for request-sequence, method and field mappings. See Changelog for release history.

AI coding agent skill

Use the official bsc-aggregator skill to build and review BSC Mainnet (56) integrations. It covers Allowance and Permit2 swaps, native BNB, fees and transaction validation, with a compatibility baseline of @masterpeach/aggregator-sdk@0.5.0 and ethers 6. Use BSC SDK/API methods, not the Arc interfaces.

Preserve the user's positive, after-fee minimum received across refreshes; changed terms need new confirmation. Confirm the trade before the payer signs Permit2: the signature itself authorizes execution. Verify spenders, recipients, transaction targets and expiry; simulate and check receipts. Never silently widen slippage, zero a minimum or blindly retry an uncertain broadcast; check its outcome first.

Example: “Use bsc-aggregator to integrate a BNB swap with a review and confirmation screen.”

The skill provides development guidance; installation does not authorize approvals, signatures or transaction submission. The application's user controls those actions. See Peach AI for source, installation and compatibility details.

Last updated

Was this helpful?