API

Buy & sell

Get an unsigned buy or sell transaction for your wallet, then sign and send it.

Also on Robinhood chain

Builds a transaction that buys or sells a coin from your wallet. We never see your private key: you sign the transaction yourself, then send it with /api/sol/send.

POSThttps://api.trenchy.tools/api/sol/trade-local

Request fields

FieldTypeDescription
publicKeystringYour wallet address (base58).
actionstringbuy or sell.
mintstringThe coin's address.
amountnumber | stringHow much. The coin's quote asset (SOL for SOL coins; USDC / the stock / the coin on a custom pair) if denominatedInSol is "true", tokens if "false". Sells also accept a share of your balance, like "100%" or "50%".
denominatedInSol"true" | "false"Whether amount is in the quote asset ("true") or in tokens ("false"). denominatedInQuote is the same switch under the name that reads right on a custom pair.
slippagenumberWorst price you accept, in percent. Default 10. Use 15–25 for coins in their first minutes.
priorityFeenumberExtra SOL to land faster. Default 0.00005.
poolstringpump (bonding curve), pump-amm (PumpSwap) or auto (we pick). Default pump; auto resolves curve vs. AMM from chain state.
partialFillbooleanMayhem coins only: a buy past the remaining supply takes what is left instead of failing. Other coins complete the curve and keep buying from the pool-to-be (synthetic migration).

Full example

import { Keypair, VersionedTransaction } from '@solana/web3.js'
import bs58 from 'bs58'

const BASE = 'https://api.trenchy.tools'
const API_KEY = 'YOUR_API_KEY'
const wallet = Keypair.fromSecretKey(bs58.decode(process.env.SOL_PRIVATE_KEY))

// 1. Ask for the transaction
const res = await fetch(`${BASE}/api/sol/trade-local?api-key=${API_KEY}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    publicKey: wallet.publicKey.toBase58(),
    action: 'buy',
    mint: 'MINT_ADDRESS',
    amount: 0.01,               // 0.01 SOL
    denominatedInSol: 'true',
    slippage: 15,
    priorityFee: 0.0001,
    pool: 'auto',
  }),
})
if (!res.ok) throw new Error((await res.json()).error)

// 2. Sign it with your own key
const tx = VersionedTransaction.deserialize(new Uint8Array(await res.arrayBuffer()))
tx.sign([wallet])

// 3. Send it through every fast lane
const sent = await fetch(`${BASE}/api/sol/send?api-key=${API_KEY}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ transaction: Buffer.from(tx.serialize()).toString('base64') }),
}).then((r) => r.json())
console.log('https://solscan.io/tx/' + sent.signature)

Response

By default the body is the raw transaction bytes (application/octet-stream). Add ?format=json to get JSON instead:

Response
{
  "transaction": "AQAAAAAAAAAAAAAA…",   // base64, unsigned
  "encoding": "base64",
  "expected": { "tokens": 291577.94, "quoteAmount": 0.01, "sol": 0.01 },   // "sol" only on SOL coins
  "feeSol": 0.00005,                        // our fee, always SOL
  "mint": "MINT_ADDRESS",
  "action": "buy",
  "quote": { "mint": "So11111111111111111111111111111111111111112", "symbol": "SOL", "decimals": 9 },
  "venue": "pump"                           // pump | pump-amm
}

Selling everything

Response
{ "publicKey": "YOUR_WALLET", "action": "sell", "mint": "MINT_ADDRESS",
  "amount": "100%", "denominatedInSol": "false", "slippage": 15, "pool": "auto" }

Coins priced in USDC, a stock or another coin

The request is the same: amount means the coin's quote asset (quote in every answer says which). Your wallet must hold it; a short balance is 409 no_quote_balance with needed, have and the token account to fund (check it with balances mint=<quote mint>). Fees are still SOL. Trades run on pump.fun's v3 instructions; pool: "auto" follows the coin to its PumpSwap pool, priced in the same asset. See Custom pairs.

Buy 25 USDC worth of a USDC-paired coin
{ "publicKey": "YOUR_WALLET", "action": "buy", "mint": "MINT_ADDRESS",
  "amount": 25, "denominatedInQuote": "true", "slippage": 15, "pool": "auto" }
Got error 6002 or 6003 when the transaction ran? The price moved more than your slippage while it was on its way. Raise slippage, or trade a little later when the coin has calmed down.