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. If the quote expires before signing, request a new one.

Step 4: Sign and execute the swap

Ask your wallet to sign the quote’s transaction. Then call POST /v1/execute with the signed transaction and the same quote identifiers.
A SUBMITTED status means the transaction is still pending. Repeat the same execution request until it returns CONFIRMED. Once confirmed, your wallet holds the USDC received from the swap. This submits a real transaction on Solana mainnet. If a request fails after submission, check txHash in a Solana explorer before starting another swap. For the full request and response schemas, see the API specification.