Direct Swaps
Use Direct Allowance when one wallet supplies the tokens and submits the swap.
Use swapAllowance() when the same wallet supplies tokens and submits the swap. It returns a PreparedDirectSwap with status TRANSACTION_READY; payer and recipient default to executor, and only the recipient may differ.
Quickstart covers preparation, review and submission. This page covers recipient selection, approval choices and simulation. See SDK Reference for all request fields.
Display the selected paths
Use prepared.raw.paths for route display and preserve the returned transaction unchanged. Path fields and optional pool visibility are described in Quotes and Routing.
Set the recipient
Use the client, signer and order inputs from Quickstart. Set recipient during fresh preparation to send the output directly to destinationAddress in the swap transaction:
const prepared = await client.swapAllowance({
from: tokenIn, target: tokenOut, amount,
executor: await signer.getAddress(),
recipient: destinationAddress,
slippageBps: 50, // 0.5%
deadlineSecs: 300,
});
if (prepared.amountIn !== amount) throw new Error("Prepared input differs from the order");The signer supplies input and pays gas; the recipient receives the output. Show the recipient, prepared.expectAmountOut and prepared.tx.amountOutMin for acceptance, then follow Quickstart's approval and submission steps.
Sending tokens to a protocol contract does not call its deposit() or stake() function. Combining a swap with such operations requires an outer contract call; that workflow has not been verified for this guide. executeSwap() sends directly to the Peach Execution Router.
Token approval
For native input or sufficient allowance, buildDirectApprovalRequest() returns undefined. Otherwise it builds approve(spender, MaxUint256). v0.5.0 has no exact-amount approval option on this helper. gasPrice and gasLimit affect the transaction envelope, not the allowance amount.
Applications choosing an exact allowance can build a separate ERC20 approval using prepared.tokenIn, prepared.approvalSpender and prepared.amountIn, then wait for its receipt. Do not approve an address from an earlier quote. Some tokens require a confirmed zero allowance before changing a nonzero allowance; this behavior is not automated by the helper.
Simulate and execute
simulateSwap() calls the prepared transaction against current RPC state, using its executor and unchanged calldata. It requires sufficient input balance and, for ERC20 input, allowance. No state overrides are supplied. The returned RouterExecutionReceipt includes userAmountOut.
executeSwap() checks the executor signer and sends the transaction. It returns an ethers TransactionResponse without waiting for mining. tx.wait() may throw on revert or replacement; inspect the outcome before displaying success.
For expiry, input changes and artifact preservation, follow Transaction Safety.
For BNB input or output, see Native BNB.
Last updated
Was this helpful?