Skip to main content
This recipe swaps 0.01 SOL for USDC.
The TypeScript examples assume you already have a connected Wallet Standard Solana wallet (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:
Load the key using your project’s environment configuration. Keep it private; for browser calls, use your app’s existing authenticated request layer.

Step 2: Choose your tokens

Call GET /v1/tokens to find token mint addresses and decimals. Requests use a Bearer token for authentication.
Use a token’s 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

Call POST /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.
This example selects the first quote. Let your user review the available quotes and choose one before continuing. A missing quote isn’t an error: 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 call POST /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.
A 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.
This submits a real transaction on Solana mainnet. After a 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, keep result.txHash and look it up on Solana:
On the 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.