TrenchyToolsAPI

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.trenchytools.lol/api/sol/trade-local

Request fields

FieldTypeDescription
publicKeystringYour wallet address (base58).
actionstringbuy or sell.
mintstringThe coin's address.
amountnumber | stringHow much. SOL 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 SOL ("true") or in tokens ("false").
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.

Full example

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

const BASE = 'https://api.trenchytools.lol'
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, "sol": 0.01 },
  "feeSol": 0.00005,
  "mint": "MINT_ADDRESS"
}

Selling everything

Response
{ "publicKey": "YOUR_WALLET", "action": "sell", "mint": "MINT_ADDRESS",
  "amount": "100%", "denominatedInSol": "false", "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.