sdk.instructions()
Get raw swap instructions for composing custom transactions. Use this when you need to add custom instructions (tips, memos, etc.) or batch multiple swaps.Parameters (InstructionsRequest)
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
userWallet | string | yes | — | User’s wallet address (base58) |
inputMint | string | yes | — | Input token mint address |
outputMint | string | yes | — | Output token mint address |
amount | string | yes | — | Amount in smallest token units |
swapMode | "ExactIn" | "ExactOut" | yes | — | Swap direction |
slippageBps | number | no | 50 | Slippage tolerance in basis points |
Response (InstructionsResponse)
Response Fields
| Field | Type | Description |
|---|---|---|
instructions | RawInstruction[] | Ordered list of Solana instructions |
addressLookupTableAddresses | string[] | ALT addresses to include in the v0 transaction |
amountIn | string | Input amount |
amountOut | string | Estimated output amount |
otherAmountThreshold | string | Slippage-adjusted threshold |
feeAmount | string | Aggregator fee in output token units |
hopCount | number | Number of swap hops |
route | string[] | Token mint path |
pools | string[] | Pool addresses used |
RawInstruction
| Field | Type | Description |
|---|---|---|
programId | string | Program ID (base58) |
accounts | RawAccountMeta[] | Account metas |
data | string | Base64-encoded instruction data |
RawAccountMeta
| Field | Type | Description |
|---|---|---|
publicKey | string | Account public key (base58) |
isSigner | boolean | Whether the account must sign |
isWritable | boolean | Whether the account is writable |
Building a Transaction
After receiving the instructions, you build the transaction yourself:When to Use instructions() vs swap()
| Use case | Endpoint |
|---|---|
| Simple swap, let the API handle everything | sdk.swap() |
| Add custom instructions (tip, memo, etc.) | sdk.instructions() |
| Batch multiple swaps in one transaction | sdk.instructions() |
| Inspect accounts and data before signing | sdk.instructions() |
| Need lower latency (no blockhash fetch server-side) | sdk.instructions() |