TrenchyToolsAPI

Buy & sell

Get the ordered transactions for a pons buy or sell, then send them in order.

Also on Solana

Returns the transactions your wallet needs, in order, unsigned. Sign and send them one after another with your own wallet. If a transaction is labeled approve, wait for it to confirm before sending the next one. Every buy and sell carries a min-out derived from the quote and your slippage, on the curve and on the v4 pool alike.

POSThttps://api.trenchytools.lol/api/rh/trade-local

Request fields

FieldTypeDescription
walletstringYour 0x address.
actionstringbuy or sell.
tokenstringThe coin's 0x address.
amountnumber | stringBuys: ETH. Sells: tokens, or a share of your balance like "100%".
slippagenumberPercent. Default 5.

Full example

import { createWalletClient, createPublicClient, http, defineChain } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const BASE = 'https://api.trenchytools.lol', API_KEY = 'YOUR_API_KEY'
const robinhood = defineChain({ id: 4663, name: 'Robinhood Chain',
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
  rpcUrls: { default: { http: ['https://rpc.mainnet.chain.robinhood.com'] } } })
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY)
const wallet = createWalletClient({ account, chain: robinhood, transport: http() })
const chain = createPublicClient({ chain: robinhood, transport: http() })

// 1. Ask for the transactions
const { transactions, expected } = await fetch(`${BASE}/api/rh/trade-local?api-key=${API_KEY}`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ wallet: account.address, action: 'buy', token: 'TOKEN_ADDRESS', amount: 0.01, slippage: 5 }),
}).then((r) => r.json())
console.log('you should get about', expected.tokens, 'tokens')

// 2. Sign and send each one, in order
for (const tx of transactions) {
  const hash = await wallet.sendTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value) })
  console.log(tx.label, hash)
  if (tx.label === 'approve' || tx.label === 'graduate') await chain.waitForTransactionReceipt({ hash })
}

Response

Response
{
  "chainId": 4663,
  "transactions": [
    { "label": "approve", "to": "0x…token", "data": "0x…", "value": "0", "gas": "55971" },
    { "label": "sell",    "to": "0x…curve", "data": "0x…", "value": "0" },
    { "label": "fee",     "to": "0x…",      "data": "0x",  "value": "162873307575", "valueEth": "0.000000162873307575" }
  ],
  "expected": { "tokens": 19761.65, "eth": 0.0000326 },
  "venue": "curve"         // curve | v4
}
labelWhat it is
approveERC-20 approve to the curve/pool. Emitted once per token, ahead of the first sell.
graduateFinishes a coin's move to its V4 pool when it is stuck halfway. Rare.
buy / sellThe trade itself.
feeOur 0.5% service fee, in ETH.