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

Native BNB

Swap native BNB and understand the sentinel address, WBNB and transaction value.

Import NATIVE_TOKEN_ADDRESS from @masterpeach/aggregator-sdk to identify native BNB. Its value, shown below, is a placeholder rather than an ERC20 contract. isNativeTokenAddress(address) recognizes it case-insensitively.

Asset
Value used in SDK token parameters
Handling

Native BNB

0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

Native balance; 18 decimals; no ERC20 approval for input

WBNB on BSC Mainnet

0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

ERC20 balance and allowance

Pass the sentinel as from or target when preparing a swap. Read native BNB balance with provider.getBalance(walletAddress) and format it with ethers.formatEther(). ERC20 helpers such as getTokenInfo() and client.getBalance() expect token contract addresses; do not pass the sentinel to them or use it as a transaction destination.

amount uses input-token base units: 18 decimals for native BNB, or the input ERC20's decimals for token-to-BNB swaps.

Supported swaps

Input → output
Direct Swaps
Delegated Swaps

ERC20 → ERC20

Supported

Supported

Native BNB → ERC20

Supported; no ERC20 approval

Unsupported

ERC20 → Native BNB

Supported

Supported

Native BNB → Native BNB

Rejected

Rejected

These are SDK capabilities. The selected deployment must also support the mode and have a route.

Swap BNB

Use the initialized client and your signer's address as the executor, as in Quickstart.

import { ethers } from "ethers";
import { NATIVE_TOKEN_ADDRESS, PeachClient } from "@masterpeach/aggregator-sdk";

export async function prepareBNBSwap(client: PeachClient, executor: string, tokenOut: string) {
  const prepared = await client.swapAllowance({
    from: NATIVE_TOKEN_ADDRESS,
    target: tokenOut,
    amount: ethers.parseEther("0.01"),
    executor,
    slippageBps: 50, // 0.5%
    deadlineSecs: 300,
  });
  return prepared;
}

After preparation, display prepared.expectAmountOut and prepared.tx.amountOutMin using output-token decimals. Once the user accepts them, follow Quickstart’s approval/submission step; the approval helper returns undefined for native input.

For native output, put an ERC20 address in from and NATIVE_TOKEN_ADDRESS in target. Use input-token decimals for the amount. Format BNB output with 18 decimals.

Addresses and transaction value

The SDK normalizes the sentinel to configured WBNB, so prepared tokenIn / tokenOut contain WBNB addresses for native requests. Use nativeMode to identify the native direction and retain the original sentinel in your order for refreshed preparation. Explicit nativeIn or nativeOut flags are also supported.

Native mode 0 means ERC20 input/output, 1 means native input, and 2 means native output. For native input the validated transaction value equals prepared input; for other modes it is zero. executeSwap() preserves that value.

Do not add BNB to an ERC20-input swap or overwrite tx.value. Native input requires enough balance for input plus gas. For ERC20 input, the executor still needs BNB for gas, and any payer approval needs gas in the payer's account.

Last updated

Was this helpful?