Forest Docs
DevelopersForest Playkit

Swaps

Swap quote, buy, and sell methods, plus the snapshot shape.

Swaps run through the connected wallet. Quote is a read; buy and sell open the wallet. Amounts are display decimal strings — see Amounts. For user-approved auto-swaps, see Swap Sessions.

Swap Methods

forest.swap.quote

Gets a read-only quote and snapshot. This does not open the wallet or submit a transaction.

JavaScript
callForest("forest.swap.quote", {
	amount: "0.05",
	direction: "buy",
	slippage: 0.5,
});

Prop

Type

forest.swap.buy

Submits a buy transaction through the connected wallet. amount is the amount of the pay token to spend.

JavaScript
callForest("forest.swap.buy", {
	amount: "0.05",
	slippage: 0.5,
});

Prop

Type

forest.swap.sell

Submits a sell transaction through the connected wallet. amount is the amount of the launched token to sell.

JavaScript
callForest("forest.swap.sell", {
	amount: "100",
	slippage: 0.5,
});

Prop

Type

Snapshot Reference

Quote and swap responses can include result.snapshot. Store the latest snapshot and render your UI from it. The base snapshot always includes direction, slippage, pay token, and receive token. Quote and route fields are present only after Forest has enough data for them.

JavaScript
{
  direction: "buy",
  slippage: 0.5,
  payToken: {
    symbol: "BNB",
    balance: 1.25,
    locked: 0
  },
  receiveToken: {
    symbol: "TOKEN"
  },
  quote: {
    payAmount: 0.05,
    receiveAmount: 1234.56,
    receivePerPay: 24691.2,
    payPerReceive: 0.0000405
  },
  priceImpact: 1.2,
  liquidityDepth: 8.7,
  swapBreakdown: {
    steps: [],
    totalEffectiveFee: 0.01,
    expectedOutput: 1234.56
  }
}

Snapshot values are display numbers, not base-unit integers.

Top-level fields

Prop

Type

payToken / receiveToken

Prop

Type

quote

When quote is present, it has:

Prop

Type

swapBreakdown

When swapBreakdown is present, it has:

Prop

Type

Calculate spendable balance from the snapshot:

JavaScript
const available = snapshot.payToken.balance - (snapshot.payToken.locked || 0);

Error handling

Quote, buy, and sell failures use the shared swap error taxonomy. See Errors and Security for each code's cause and resolution.