Integrate on Solana
For Solana swaps, use the Solana Trading SDK or integrate directly with the Solana Order Book API.
The Solana integration is in alpha, so program versions and APIs can change. Both staging and production use Solana mainnet-beta and real tokens; use a separate wallet with small amounts for testing.
Choose an Environment
Select the environment with the SDK's env option:
| Environment | Order Book API base URL | SDK option |
|---|---|---|
| Production | https://api.cow.fi/solana | { env: 'prod' } |
| Staging (barn) | https://barn.api.cow.fi/solana | { env: 'staging' } |
import { SolanaTradingSdk } from '@cowprotocol/sdk-trading-solana'
const sdk = new SolanaTradingSdk({ env: 'prod' })
Order Creation
The user signs a creation transaction in both flows:
| Subsidised (sponsored) | Non-subsidised (user-funded) | |
|---|---|---|
| Creation transaction fee and order account rent | Paid by CoW's sponsor | Paid by the user |
| Signatures | User signs first; CoW adds the sponsor's signature | User signs as owner and fee payer |
| Submission | Order Book API | Solana RPC |
Order creation locks SOL as rent in the order account. After the order is filled, cancelled, or expired, ReclaimOrder can close the account and return the rent to its original payer (created_by). This is the sponsor for sponsored orders or the user for user-funded orders.
Sponsored Orders
Use the quote's funder as fee payer and order account rent payer. If it is absent or null, use the user-funded flow.
The user signs, leaving the sponsor's signature empty. Submit the base64-encoded transaction as partiallySignedTx to POST /api/v1/orders. CoW adds the sponsor's signature and submits it. See the API quickstart.
User-funded Orders
The user pays fees and account rent in SOL. Sign and submit the transaction through Solana RPC. The Order Book API indexes the order from the chain, so no API submission is needed.
See the SDK quickstart or Node.js example.
Order Lifecycle
- Get a quote: Specify tokens, amount, owner, and order kind. Check the quote's
expiration. - Build the transaction: Approve the sell tokens and add
CreateOrder. Wrap native SOL into wSOL when selling it. - Sign and submit: Use either flow above and save the order UID.
- Wait for settlement: Solvers compete to fill the order after creation.
- Track the order: Check its status and executed amounts until fulfilled, cancelled, or expired.
Use approveCowProtocol to approve the settlement state account as delegate. Check the delegate and remaining allowance before each trade; fills reduce the allowance.
A token account has only one delegate. Approving another app on the same sell-token account replaces CoW's delegation and can prevent open orders from settling. Use approveCowProtocol to restore CoW's delegate and sufficient allowance.
Settlement buffers hold the buy tokens before the program pays them to the user. For SPL token buys, ensure the buffer for the buy mint exists. Create a missing buffer with CreateBuffers, using a payer funded with SOL for its rent. This is separate from the order account rent.
The SDK example buys native SOL, whose buffer is created during program initialization, so it needs no buffer creation step.
Expiration and Cancellation
Orders expire at validTo (Unix seconds). Creation transactions must land within the blockhash's 150-block lifetime, roughly 30 seconds at 200 ms per slot. CoW Swap allows 20 seconds for signing, leaving 10 seconds for submission.
If the transaction expires, get a fresh quote and transaction. Once created, the order stays open until filled, cancelled, or validTo.
Cancel with an owner-signed CancelOrder transaction. The SDK's cancelOrder also supports cancellation before creation lands.
Track an Order
Use the SDK's orderId as the UID in GET /api/v1/orders/{uid}, as shown in the API quickstart.
RPC-submitted orders may return 404 before indexing. Keep the transaction signature to check confirmation through RPC.
Poll while the order is open:
| Status | Meaning |
|---|---|
open | Still open; may have partial fills |
fulfilled | Fully filled |
cancelled | Cancelled |
expired | The order or its pending creation transaction expired |
executedSellAmount and executedBuyAmount are decimal strings in token base units (1000000 = 1 USDC).
GET /api/v1/orders/{uid}/status shows auction progress. Its traded type does not mean the order is fully filled; check the order's status. Use GET /api/v2/trades?orderUid={uid} for trades and transaction signatures.
Link to CoW Explorer
Use orderId in the explorer URL. It is the same 0x-prefixed, 32-byte UID format in both environments, distinct from the order account address or transaction signature.
Production: https://explorer.cow.fi/solana/orders/{uid}
Staging: https://barn.explorer.cow.fi/solana/orders/{uid}