Skip to main content
Code examples for common swap scenarios using the Stableswapper program.
These examples assume you’ve completed the Quickstart setup steps (dependencies, environment variables, and IDL/ABI).

Setup

Use these Base Sepolia addresses in your examples. For mainnet, replace with your production addresses from Key Addresses.

Swap USDC for custom token


Swap custom token for USDC


Swap to a different recipient

On Base, you can send swap output directly to another address by specifying a different recipient.

Query contract state

Read contract state before executing swaps for validation and fee calculation.

Swap between two custom stablecoins

The contract supports swapping between any two listed and swappable tokens — not just USDC pairs. To swap between two custom stablecoins, use their respective addresses as tokenIn and tokenOut. Both tokens must be listed and have swapping enabled.

Reference

Complete swap instruction parameters and accounts

Production Readiness

Helper functions and best practices

Quickstart

Get up and running in 10 minutes

Key Addresses

Program IDs and deployed addresses