Quick Start
Fetch live state, preview a buy, build the instructions, and assemble an unsigned transaction.
SDK
From connection to first buy
The shortest useful workflow is: load the curve state, preview the trade, build the instruction array, then assemble the unsigned transaction you want the wallet to sign.
This example requires the SDK and programs described on the installation page. The quote describes the fetched state, not a guaranteed fill.
import { DumpsterClient } from '@dumpster-cash/dumpster-sdk';
import { Connection, PublicKey } from '@solana/web3.js';
import BN from 'bn.js';
const connection = new Connection('https://rpc.gorbagana.wtf');
const client = new DumpsterClient(connection);
const mint = new PublicKey('...');
const user = new PublicKey('...');
const gorAmount = new BN(1_000_000_000);
const state = await client.accounts.fetchCurveTradeState(mint, user);
const preview = client.preview.curveBuy({
feeConfig: state.feeConfig,
bondingCurve: state.bondingCurve,
amountInGor: gorAmount,
});
if (preview.amountOutTokens.isZero()) throw new Error('Budget buys no tokens');
const instructions = await client.curve.buildBuyExactOut({
global: state.global,
bondingCurve: state.bondingCurve,
associatedUserAccountInfo: state.associatedUserAccountInfo ?? null,
mint,
user,
amount: preview.amountOutTokens,
gorAmount: preview.amountInGor,
slippage: 1,
});
const tx = await client.tx.buildTransaction(instructions, {
feePayer: user,
computeUnits: 300_000,
});What this does
- loads the global config, fee config, curve account, and user ATA state in one call
- computes the greatest affordable output and actual trade cost from that paired snapshot
- builds the instruction array for a curve buy
- assembles an unsigned transaction with a compute budget
The entered GOR amount is a budget; preview.amountInGor is the actual trade spend. slippage: 1 permits 1% above that cost, so it is not an absolute wallet spending cap. Network fees and account deposits are additional.
Convenience path
If you do not want to wire the state bundle yourself, use the AutoResolve builder:
const instructions = await client.curve.buildBuyExactOutAutoResolve({
connection,
mint,
user,
amount: preview.amountOutTokens,
gorAmount: preview.amountInGor,
slippage: 1,
});The explicit path is better when you are already holding fresh state in memory. The AutoResolve path is better for short scripts and simpler integrations.