Skip to main content

Integrate on Solana

For Solana swaps and limit orders, use the Solana Trading SDK or integrate directly with the Solana Order Book API.

Alpha integration

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:

EnvironmentOrder Book API base URLSDK option
Productionhttps://api.cow.fi/solana{ env: 'prod' }
Staging (barn)https://barn.api.cow.fi/solana{ env: 'staging' }

See the settlement program addresses for production and staging.

import { SolanaTradingSdk } from '@cowprotocol/sdk-trading-solana'
const sdk = new SolanaTradingSdk({ env: 'prod' })

Order Creation​

Orders can be sponsored or user-funded. The user signs the creation transaction in both flows.

Subsidised (sponsored)Non-subsidised (user-funded)
Creation transaction fee and order account rentPaid by CoW's sponsorPaid by the user
SignaturesUser signs first; CoW adds the sponsor's signatureUser signs as owner and fee payer
SubmissionOrder Book APISolana RPC
Order typesMarket ordersMarket and limit orders

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 market orders need a valid quote with enough slippage to settle. Limit orders use the user-funded flow.

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 when the order wins an auction. See the API quickstart.

The transaction must follow these rules:

  • End with a CreateOrder instruction.
  • When selling native SOL, create, fund, and sync the wrapped-SOL account as needed before approval. The user pays its rent.
  • Approve the settlement delegate before CreateOrder if needed.
  • Do not create the buy token account. Settlement can create the owner's missing associated token account. A custom receiver's buy token account must already exist.
  • Do not include unrelated instructions. See the transaction requirements for the accepted preparation steps and signing format.

Native SOL buys pay the wallet directly, so no buy token account is needed.

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.

Limit Orders​

Limit orders trade at your chosen price or better. Set sellAmount and buyAmount to define the price, and validTo for expiry. They use the user-funded flow and do not need a quote. See the SDK limit order example.

Order Lifecycle​

See Flow of an order for auctions and settlement. On Solana, users sign order creation transactions. User-funded orders enter auctions after creation is indexed. Sponsored orders can enter before their creation transaction lands.

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, rebuild it with a fresh blockhash and, for swaps, a fresh quote. 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 monitoring example. The Solana UID is a 0x-prefixed, 32-byte value, distinct from the order account address or transaction signature.

RPC-submitted orders may return 404 before indexing. Keep the transaction signature to check confirmation through RPC.

View orders at https://explorer.cow.fi/solana/orders/{uid} in production or https://barn.explorer.cow.fi/solana/orders/{uid} in staging.