TrenchyToolsAPI

Account (nonce & gas)

Nonce, gas prices, chain id and ETH balance for one wallet: what a local signer needs

EVM transactions are signed with a nonce and gas prices that only the chain knows. This call returns them for a wallet so your bot can sign trade-local transactions, plain ETH transfers and exchange deposits without an RPC node.

GEThttps://api.trenchytools.lol/api/rh/account
FieldTypeDescription
walletstringAny 0x address.
Request
curl "https://api.trenchytools.lol/api/rh/account?wallet=0xYOUR_WALLET&api-key=YOUR_KEY"
Response
{
  "wallet": "0x…", "chainId": 4663, "nonce": 12, "pendingNonce": 12, "balanceEth": "0.0683", "block": 95493312,
  "gasPrice": "10000000", "maxFeePerGas": "12000000", "maxPriorityFeePerGas": "0", "transferGas": "21000",
  "note": "Sign with chainId + pendingNonce (+1 per transaction you send in a row) and these fee values; a plain ETH transfer is {to, value, gas: 21000}."
}
Sign and send a trade-local answer (viem)
import { createWalletClient, http, parseGwei } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const account = privateKeyToAccount(process.env.PK as `0x${string}`)
const api = (p: string, init?: RequestInit) => fetch(`https://api.trenchytools.lol${p}${p.includes('?') ? '&' : '?'}api-key=${process.env.KEY}`, init).then(r => r.json())

const built = await api('/api/rh/trade-local', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ wallet: account.address, action: 'buy', token: '0x…', amount: 0.01 }) })
const acct = await api(`/api/rh/account?wallet=${account.address}`)
let nonce = acct.pendingNonce
for (const tx of built.transactions) {               // in order: approve → trade → fee
  const raw = await account.signTransaction({ chainId: acct.chainId, nonce: nonce++, to: tx.to, data: tx.data, value: BigInt(tx.value), gas: BigInt(tx.gas ?? 300000), maxFeePerGas: BigInt(acct.maxFeePerGas), maxPriorityFeePerGas: BigInt(acct.maxPriorityFeePerGas) })
  const { hash } = await api('/api/rh/send', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ transaction: raw }) })
  console.log(tx.label, hash)
}
Sending several transactions in a row? Take pendingNonce once and add 1 per transaction. If a send fails with a nonce error, read the account again.