This recipe swaps 0.01 SOL for USDC.
wallet) and its account (account). Your wallet needs SOL for the swap and network fees. Install @solana/kit for the transaction encoding helpers used below.
Step 1: Request an API key
Contact contact@sunrise.xyz to request a Sunrise API key for your app. Save it in your project’s.env file:
Step 2: Choose your tokens
CallGET /v1/tokens to find token mint addresses and decimals. Requests use a Bearer token for authentication.
address as its mint address. Native SOL uses "native". For this recipe, use SOL as the input and the Solana USDC mint as the output.
Step 3: Get a quote
CallPOST /v1/quotes with your token pair, amount, and wallet addresses. Include both addresses to receive an unsigned transaction you can sign.
Amounts are strings in base units. SOL has 9 decimals, so "10000000" means 0.01 SOL.
unavailableRoutes lists each route that gave none, with a code and a message you can show your user. See Errors.
Step 4: Sign, execute, and track the status
Ask your wallet to sign the quote’s transaction. Then callPOST /v1/execute with the required signedTransaction, quoteId, and routeName. Copy quoteId and routeName from the selected quote. Include the optional providerRequestId when the quote provides it.
SUBMITTED status means the transaction is still pending. The loop repeats the same request until it returns CONFIRMED. Once confirmed, your wallet holds the USDC received from the swap.
On the
rfq-fill route, CONFIRMED means that your order is open, not that it filled. Keep sending the same request until data.done is true. See RFQ orders.5xx or no answer, the order may already have been sent, so the loop sends the same request again and never signs a new quote. Sending the same request again is safe: a signed transaction is executed at most once. Every error code and its next step is listed in Errors.
Step 5: Get the swap status later
To check a swap after the loop has ended, for example after a page reload, keepresult.txHash and look it up on Solana:
rfq-fill route, the transaction only opens the order. To read the order’s result later, use GET /v1/orders. See Get order status later.
For the full request and response schemas, see the API specification.