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.
Step 4: Sign and execute the swap
Ask your wallet to sign the quote’s transaction. Then callPOST /v1/execute with the signed transaction and the same quote identifiers.
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.
