Swap
Swap
The swap surface is a thin passthrough to Jupiter's aggregator: one endpoint to request a quote, one to build the swap transaction. The Pirate API does not re-route or re-price — you get Jupiter's native response, wrapped in the standard { data, meta } envelope. This page covers the two endpoints, the slippage / ExactIn-vs-ExactOut knobs, and a SOL → GOLD example.
Lifecycle
The quote is valid for ~30 seconds in practice — Jupiter's response carries a context_slot. If you wait too long before calling POST /v2/swaps, the route may stop being executable and you'll need to re-quote.
Endpoints
| Method | Path | Purpose |
|---|---|---|
POST | /v2/swap-quotes | Get a Jupiter route + output-amount estimate |
POST | /v2/swaps | Build the signed-ready VersionedTransaction for that quote |
Neither endpoint takes a mode field — they don't sign. The client always signs and submits via POST /v2/transactions.
Quote parameters
The quote endpoint is body-based:
| Body field | Required | Default | Notes |
|---|---|---|---|
input_mint | yes | — | Mint of the token you're spending |
output_mint | yes | — | Mint of the token you want |
amount | yes | — | Decimal string of raw units of input_mint (lamports / token-decimals) |
slippage_bps | no | 50 | Max acceptable slippage; 50 = 0.5%, 100 = 1%, etc. |
swap_mode | no | ExactIn | ExactIn — fix input amount, output floats. ExactOut — fix output, input floats. |
Quote example: 0.1 SOL → GOLD
amount is in lamports (0.1 SOL = 100_000_000):
curl -X POST https://api.piratecrew.fun/v2/swap-quotes \
-H "Authorization: Bearer $PIRATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input_mint": "So11111111111111111111111111111111111111112",
"output_mint": "GoLDDqDRHcGZBiGPeXAYi5ougndqBNQSNXdNeT3re6gr",
"amount": "100000000",
"slippage_bps": 50,
"swap_mode": "ExactIn"
}'{
"data": {
"input_mint": "So11111111111111111111111111111111111111112",
"in_amount": "100000000",
"output_mint": "GoLDDqDRHcGZBiGPeXAYi5ougndqBNQSNXdNeT3re6gr",
"out_amount": "84371320",
"other_amount_threshold": "83949463",
"swap_mode": "ExactIn",
"slippage_bps": 50,
"price_impact_pct": "0.0021",
"route_plan": [
{
"swap_info": {
"amm_key": "AMM…",
"label": "Meteora DAMM v2",
"input_mint": "So11111111111111111111111111111111111111112",
"output_mint": "GoLDDqDRHcGZBiGPeXAYi5ougndqBNQSNXdNeT3re6gr",
"in_amount": "100000000",
"out_amount": "84371320",
"fee_amount": "300000",
"fee_mint": "So11111111111111111111111111111111111111112"
},
"percent": 100
}
],
"context_slot": "271234567",
"time_taken": 0.087
},
"meta": { "request_id": "req_…" }
}This is Jupiter's native route envelope, mapped to snake_case. Forward the whole data object to POST /v2/swaps without touching it.
Building the swap transaction
curl -X POST https://api.piratecrew.fun/v2/swaps \
-H "Authorization: Bearer $PIRATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_public_key": "YOUR_WALLET_PUBKEY",
"quote_response": { /* paste the entire quote.data object here */ },
"wrap_and_unwrap_sol": true,
"as_legacy_transaction": false
}'| Body field | Required | Default | Notes |
|---|---|---|---|
user_public_key | yes | — | The wallet that will sign and pay for the swap |
quote_response | yes | — | The full object returned under data by POST /v2/swap-quotes — pass it through verbatim |
wrap_and_unwrap_sol | no | true | Auto-wrap SOL → wSOL and unwrap on exit; set false if you already manage wSOL ATAs |
as_legacy_transaction | no | false | Return a legacy tx instead of a VersionedTransaction (for older wallets) |
Response:
{
"data": {
"swap_transaction": "AQABAo...",
"last_valid_block_height": "271340000",
"prioritization_fee_lamports": "5000"
},
"meta": { "request_id": "req_…" }
}Sign swap_transaction with your wallet and submit it the same way as any other unsigned transaction from the API:
curl -X POST https://api.piratecrew.fun/v2/transactions \
-H "Authorization: Bearer $PIRATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "transaction": "<base64 signed swap_transaction>" }'ExactIn vs ExactOut
ExactIn(default): "I want to spend exactlyamountofinput_mint; tell me how muchoutput_mintI'll get." Useful when budgeting input — e.g. "swap 0.1 SOL for as much GOLD as possible."ExactOut: "I need exactlyamountofoutput_mint; tell me how muchinput_mintI'll have to spend." Useful when paying a fixed price — e.g. "I owe 100 GOLD; quote me the SOL cost."
In ExactOut mode, amount denominates the output mint and other_amount_threshold becomes the maximum-input cap (instead of minimum-output as in ExactIn).
Reference
- Transaction Modes — submitting the signed swap tx.
- Tokens — mint addresses for any token you want to route.
- Jupiter docs: https://station.jup.ag/docs/apis/swap-api — the upstream contract these endpoints mirror.
- Live schema:
/v2/docs.