Swap Permit2
Prepare a Permit2 swap with a quote, frozen plan and payer signing data.
Return a quote, frozen plan and payer signing material. This is the first Permit2 request; SDK method: swapPermit2(). Supply different payer and executor addresses and an explicit recipient. Only ERC20 input is supported. Review and sign the returned Permit2 witness typed data, then submit the quote ID and payer signature to POST /router/swap/permit2/build. No separate quote request is required.
Compatibility alias: /router/swap/prepare. Production deployment of the new endpoint has not been verified.
Input ERC20 token address. Use WBNB for native BNB routing.
0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095cPattern: ^0x[0-9a-fA-F]{40}$Output ERC20 token address; must differ from from. Use WBNB for native BNB routing.
0x55d398326f99059fF775485246999027B3197955Pattern: ^0x[0-9a-fA-F]{40}$Positive unsigned integer, at most 2^128 - 1, in input-token base units for the documented exact-input flow. Send decimal digits, never a human-readable fractional amount.
10000000000000000Pattern: ^[0-9]+$Use true for the documented exact-input v7 workflow. Omission defaults to true. A legacy false flag can be parsed by the server but does not establish supported exact-output behavior.
trueExample: truePossible values: Maximum route hops. Omission or 0 uses the service routing configuration; values above its maximum are rejected.
3Requested split count. Omission or 0 uses the configured maximum; the service can reduce it for trade size and metadata availability.
20Comma-separated provider identifiers from Get Status. Omit to use the enabled provider set; availability and version filters still apply.
PANCAKEV3,PANCAKEV2Accepted for routing compatibility; swap endpoints do not apply the find_routes minimum-version gate.
1001500Optional gas limit override. Prefer the service estimate unless you have measured the complete execution path.
Optional advanced path-calculation limit; behavior follows the service routing configuration.
Transaction sender signed into the plan. executor or its compatibility alias sender is required. Submit the returned transaction from this address. Must be nonzero and differ from the execution router.
0x1111111111111111111111111111111111111111Pattern: ^0x[0-9a-fA-F]{40}$Compatibility alias for executor. Prefer executor and send only one of the two fields. Must be nonzero and differ from the execution router.
^0x[0-9a-fA-F]{40}$ERC20 token owner; must differ from executor for delegated preparation. Must be nonzero and differ from the execution router.
0x2222222222222222222222222222222222222222Pattern: ^0x[0-9a-fA-F]{40}$Output recipient. Required when payer differs from executor. Must be nonzero and differ from the execution router.
0x3333333333333333333333333333333333333333Pattern: ^0x[0-9a-fA-F]{40}$Custom fee deducted from gross output, in basis points (100 bps=1%). Omission/0 means no fee. Must not exceed peach_router.max_custom_fee_bps from Get Status. Fees require by_amount_in=true.
0Required when custom_fee_bps>0. Must be nonzero and differ from the execution router and recipient. For native BNB output use a recipient able to receive BNB; the service rejects contract fee receivers when its optional code check identifies one.
^0x[0-9a-fA-F]{40}$Slippage applied to expected net output after the custom fee: floor(expect_amount_out*(10000-slippage_bps)/10000). Omission uses service configuration (code fallback 50 bps=0.5%).
50Expiry offset in seconds. Delegated preparation requires 1..configured maximum (code fallback maximum 300). Omission uses the configured default (code fallback 120).
120Must be false for delegated funding; native BNB input is unsupported.
falseExample: falseSet true for native BNB output and pass WBNB as target. Cannot be combined with native_in=true.
falseExample: falseApplication success (code=200) or application error (code!=200). Business errors may still have HTTP status 200; inspect the JSON code.
Malformed query or request rejected by HTTP extraction. Body may be plain text rather than an application envelope.
Unhandled service failure.
Service-wide rate limit / circuit breaking. Retry with backoff.
# Set PAYER, EXECUTOR and RECIPIENT to the intended BSC addresses.
# PAYER must differ from EXECUTOR. This example pays 1 USDT (18 decimals)
# and requests native BNB output by routing through WBNB.
: "${PAYER:?Set PAYER to the token owner address}"
: "${EXECUTOR:?Set EXECUTOR to the transaction sender address}"
: "${RECIPIENT:?Set RECIPIENT to the output recipient address}"
curl --fail-with-body --silent --show-error --get \
'https://api.peach.ag/router/swap/permit2' \
--data-urlencode 'from=0x55d398326f99059fF775485246999027B3197955' \
--data-urlencode 'target=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' \
--data-urlencode 'amount=1000000000000000000' \
--data-urlencode "payer=$PAYER" \
--data-urlencode "executor=$EXECUTOR" \
--data-urlencode "recipient=$RECIPIENT" \
--data-urlencode 'by_amount_in=true' \
--data-urlencode 'v=1001500' \
--data-urlencode 'slippage_bps=50' \
--data-urlencode 'deadline_secs=300' \
--data-urlencode 'native_in=false' \
--data-urlencode 'native_out=true'
# Review and sign the returned typed_data as PAYER before calling build.
{
"code": 200,
"msg": "Success",
"data": {
"request_id": "text",
"quote_id": "text",
"quote_ts": 1,
"amount_in": "text",
"amount_out": "text",
"expect_amount_out": "text",
"amount_out_min": "text",
"payer": "text",
"executor": "text",
"recipient": "text",
"gas": 1,
"execution_mode": "PERMIT2_WITNESS",
"execution_status": "PAYER_SIGNATURE_REQUIRED",
"plan_hash": "text",
"aggregator_signature": "text",
"aggregator_signer": "text",
"payer_authorization": {
"scheme": "PERMIT2_WITNESS_TRANSFER",
"owner": "text",
"permit2": "0x000000000022d473030f116ddee9f6b43ac78ba3",
"spender": "text",
"token": "text",
"amount": "text",
"nonce": "text",
"deadline": 1,
"witness_plan_hash": "text",
"typed_data": {
"domain": {
"name": "Permit2",
"chainId": "56",
"verifyingContract": "0x000000000022d473030f116ddee9f6b43ac78ba3"
},
"types": {
"ANY_ADDITIONAL_PROPERTY": [
{
"name": "text",
"type": "text"
}
]
},
"primaryType": "PermitWitnessTransferFrom",
"message": {
"permitted": {
"token": "text",
"amount": "text"
},
"spender": "text",
"nonce": "text",
"deadline": "text",
"witness": {
"planHash": "text"
}
}
}
}
}
}Integration notes
Supply distinct payer and executor addresses (or the sender alias), plus an explicit recipient. Only ERC20 input is supported (native_in=false); native output uses WBNB in target with native_out=true.
The payer approves the input ERC20 to canonical Permit2, reviews and signs payer_authorization.typed_data, then sends the returned quote_id and signature to Swap Permit2 Build. The raw amount_out_min is not a substitute for validation against signed calldata after build. Each preparation creates a new plan; keep its artifacts together. This endpoint does not broadcast.
The payer signature authorizes the frozen plan. See Delegated Swaps for the signing boundary.
Check both the HTTP status and JSON code; a business error may use HTTP 200. See Error Codes for recovery guidance. Invalid query or body extraction may return plain text instead of the JSON envelope.
Last updated
Was this helpful?