跳转到主要内容
POST
/
v1
/
swap
/
swap
curl --request POST \ --url https://payments.magicblock.app/v1/swap/swap \ --header 'Content-Type: application/json' \ --data ' { "userPublicKey": "3rXKwQ1kpjBd5tdcco32qsvqUh1BnZjcYnS5kYrP7AYE", "quoteResponse": { "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "inAmount": "1000000", "outputMint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", "outAmount": "999519", "otherAmountThreshold": "994522", "swapMode": "ExactIn", "slippageBps": 50, "priceImpactPct": "0", "routePlan": [] } } '
{ "swapTransaction": "AQABA...base64...", "lastValidBlockHeight": 318120000 }

请求体

application/json
userPublicKey
string
必填

Public key of the wallet that will sign the swap transaction.

示例:

"3rXKwQ1kpjBd5tdcco32qsvqUh1BnZjcYnS5kYrP7AYE"

quoteResponse
object
必填

Quote response from GET /v1/swap/quote.

payer
string

Optional fee payer for transaction fees and rent.

示例:

"3rXKwQ1kpjBd5tdcco32qsvqUh1BnZjcYnS5kYrP7AYE"

wrapAndUnwrapSol
boolean

Automatically wrap and unwrap native SOL when needed.

示例:

true

useSharedAccounts
boolean

Allow shared accounts for intermediate routing state.

示例:

true

feeAccount
string

Optional initialized token account used to collect platform fees.

trackingAccount
string

Optional public key used for downstream transaction tracking.

prioritizationFeeLamports

Optional priority fee configuration or fixed lamport amount.

必填范围: x >= 0
asLegacyTransaction
boolean

Build a legacy transaction instead of a versioned one. Not allowed when visibility = "private".

destinationTokenAccount
string

Optional destination token account for the output mint. When visibility = "private", this is server-controlled and must match the derived stash ATA.

nativeDestinationAccount
string

Optional destination account for native SOL output. Not supported when visibility = "private".

dynamicComputeUnitLimit
boolean

Estimate compute usage and set the compute unit limit automatically.

skipUserAccountsRpcCalls
boolean

Skip extra RPC checks for required user accounts.

dynamicSlippage
boolean

Let the upstream swap builder overwrite slippage on the transaction.

computeUnitPriceMicroLamports
integer

Optional exact compute unit price in micro-lamports.

必填范围: x >= 0
blockhashSlotsToExpiry
integer

Optional transaction expiry window in slots.

必填范围: x >= 0
positiveSlippage
object

Optional positive slippage collection settings.

visibility
enum<string>

public (default) proxies Jupiter/Metis as-is. private routes the output through a scheduled private transfer.

可用选项:
public,
private
示例:

"public"

destination
string

Final private-transfer recipient (wallet pubkey). Required when visibility = "private".

minDelayMs
string

Earliest (ms) the queued transfer may settle. Required when visibility = "private".

Pattern: ^\d+$
示例:

"0"

maxDelayMs
string

Latest (ms) the queued transfer may settle. Required when visibility = "private". Must be >= minDelayMs and <= 600000 (10 minutes).

Pattern: ^\d+$
示例:

"60000"

split
integer

Number of queue entries to split the transfer across. Required when visibility = "private". Must be between 1 and 14.

必填范围: 1 <= x <= 14
clientRefId
string

Optional u64 client correlation id attached to each queued split.

Pattern: ^\d+$
validator
string

Optional validator pubkey for the transfer-queue PDA. Defaults to the well-known MagicBlock validator (MAS1Dt9qreoRMQ14YQuhg8UTZMMzDdKhmkZMECCzk57).

响应

Swap transaction

swapTransaction
string
必填

Base64-encoded unsigned transaction.

lastValidBlockHeight
integer
必填范围: x >= 0
prioritizationFeeLamports
integer
必填范围: x >= 0
privateTransfer
object

Present only when visibility = "private". Diagnostic metadata about the appended schedule_private_transfer instruction.