Skip to main content
This guide walks you through connecting a user, placing a buy on the Trench bonding curve, and confirming that it landed on-chain.

Prerequisites

Before starting, make sure you have:
  • An app registered at tren.ch/partner, which gives you a client_id and an API key. See Registration.
  • A redirect URI on the app, matching exactly what you will send.
  • The profile:read and trade:execute scopes selected for the app.
  • A Trench user to connect, with 1-click trading enabled and some SOL in their wallet.
  • A Solana RPC endpoint, which you will use to confirm that trades landed.
Trench does not provide a sandbox environment. A client in development status trades real SOL against mainnet, so we recommend testing with small amounts on a wallet you control.

Endpoints Used

1. Set Up Environment Variables

Your API key should only ever be used server-side. If it reaches a browser bundle, treat it as compromised: create a replacement key in the portal, deploy it, then revoke the leaked one.

2. Connect a User

Run the connect flow to obtain an authorization code, then exchange that code for a token pair.
cURL
Store the returned access_token and refresh_token against your own user record.

3. Verify the Token

cURL
There are two things worth checking before you attempt a trade: that tradingEnabled is true, and that scopes includes trade:execute. Keep walletSolana on hand as well, since you will need it to read the user’s balances and transaction history from your RPC.

4. Place a Buy

All amounts are sent as integer strings in base units, using lamports for SOL and 1e6 units for tokens. See Amount Conventions for details.
Response
slippageBps is your protection against the price moving between quoting and execution. Trench takes a quote when the trade executes, derives the minimum tokens it must return, and fails with slippage_exceeded rather than filling worse. If you would rather compute that bound yourself, omit slippageBps and send minTokensOut instead.
If you want to take a cut of the trade, add partnerFeeBps to the request body. See Partner Fees.

5. Confirm It Landed

A status of submitted means the network accepted the transaction, not that it succeeded. Confirmation is public on-chain state, so you read it from Solana directly using the signature Trench returned.
Node.js
Once the transaction has confirmed, the token balance changes recorded on it tell you what the user actually received.
Node.js
The Partner API does not support idempotency keys, so sending the same trade twice will execute it twice. If a request times out before you receive a signature, check the user’s recent transactions on-chain to see whether it landed before trying again.

Next Steps

Trade Tokens

Exact-out buys, sells, and volume caps.

Partner Fees

Charge your own fee on every trade.

Governance

Read proposals and vote on behalf of a user.

Security Requirements

Recommended reading before going to production.