Sell Tokens (Legacy)
How to sell tokens to a Vertigo pool
Overview
Quick Example
import { Vertigo } from "@vertigo-amm/vertigo-sdk";
import { Connection, PublicKey } from "@solana/web3.js";
import * as anchor from "@coral-xyz/anchor";
import { NATIVE_MINT } from "@solana/spl-token";
async function main() {
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
const walletKeypair = anchor.Wallet.local();
const vertigo = await Vertigo.load({
connection,
wallet: walletKeypair,
network: "devnet",
});
const tokenMint = new PublicKey("<token-mint-address>");
const DECIMALS = 6;
// Sell 100,000 tokens for SOL
const sellAmount = 100_000 * (10 ** DECIMALS);
// Get a quote first
const quote = await vertigo.swap.getQuote({
inputMint: tokenMint, // Token you're selling
outputMint: NATIVE_MINT, // SOL you're receiving
amount: sellAmount,
slippageBps: 50, // 0.5% slippage
});
console.log(`Selling ${100_000} tokens`);
console.log(`Expected to receive: ~${quote.outputAmount / 1e9} SOL`);
console.log(`Minimum received: ${quote.minimumReceived / 1e9} SOL`);
// Execute the swap
const result = await vertigo.swap.swap({
inputMint: tokenMint,
outputMint: NATIVE_MINT,
amount: sellAmount,
options: {
slippageBps: 100, // 1% slippage tolerance
priorityFee: "auto", // Auto-calculate priority fee
},
});
console.log(`Swap successful!`);
console.log(`Sold tokens for ${result.outputAmount / 1e9} SOL`);
console.log(`Transaction: ${result.signature}`);
}
main();Key Differences from v1
v1 (Old)
v2 (New)
Benefits of the Unified Interface
Additional Features in v2
Migration Guide
Full Documentation
Last updated

