Building transactions
The quote → plan → sign → tracking flow used by the site, also available to your app. The server never signs or broadcasts transactions.
Flow
- 1.
POST /v1/quotes(headerIdempotency-Key8–128 characters): the server reads on-chain state, computes output, minimum and costs, then simulates the final transaction from your wallet. - 2. If
requiresApproval, send theapprovalstransactions (approval for the transaction amount) and request the quote again. - 3.
POST /v1/transaction-planswithquoteId→ unsigned transaction{ id, to, data, value }. - 4. Sign & send from the wallet, then report the hash:
POST /v1/transactions/:id/submissions. - 5. Watch
GET /v1/transactions/:id(submitted → confirmed → finalized / failed) or receive the SSE/webhook eventtransaction.finalized.
Example: swap ETH → USDC on Base
ts
import { createWalletClient, http } from 'viem';
import { base } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
const API = 'https://banipool.com/api/v1';
const ETH = '0x0000000000000000000000000000000000000000';
const USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as `0x${string}`);
const wallet = createWalletClient({ account, chain: base, transport: http() });
const auth = { authorization: `Bearer ${process.env.BANIPOOL_SESSION}`, 'content-type': 'application/json' };
// Rute terbaik (1–2 langkah)
const route = await fetch(`${API}/swap-routes`, { method: 'POST', headers: auth,
body: JSON.stringify({ chainRef: 'eip155:8453', tokenIn: ETH, tokenOut: USDC, amountIn: '1000000000000000' }) }).then((r) => r.json());
const [first, second] = route.data.steps;
// Quote (disimulasikan di mainnet dari wallet Anda)
const quote = await fetch(`${API}/quotes`, { method: 'POST',
headers: { ...auth, 'idempotency-key': crypto.randomUUID() },
body: JSON.stringify({ action: 'swap', deploymentId: first.deploymentId, poolAddress: first.poolAddress,
tokenIn: ETH, amountIn: '1000000000000000', unwrapNative: false, slippageBps: 100,
...(second ? { viaDeploymentId: second.deploymentId, viaPoolAddress: second.poolAddress } : {}) }) }).then((r) => r.json());
console.log('minimum:', quote.data.swap.minOut, 'fee platform:', quote.data.platformFee);
// Plan → tanda tangan → laporkan hash
const plan = await fetch(`${API}/transaction-plans`, { method: 'POST', headers: auth,
body: JSON.stringify({ quoteId: quote.data.id }) }).then((r) => r.json());
const hash = await wallet.sendTransaction({ to: plan.data.to, data: plan.data.data, value: BigInt(plan.data.value) });
await fetch(`${API}/transactions/${plan.data.id}/submissions`, { method: 'POST', headers: auth, body: JSON.stringify({ txHash: hash }) });Always show the minimum output, costs and contract address to users before signing. Never put private keys in frontend code.
Supported actions
| Action | Description |
|---|---|
swap | Swap tokens through a pool (1–2 hops in one transaction). |
mint / add | Open a new position or add liquidity to a position. |
mint + createPool | Create a new pool together with its first liquidity (createPool: true, initialPrice = token1 per token0; v4 also tickSpacing). Check first with GET /v1/pool-create/check. Zap In (pay with one token): get a plan from POST /v1/pool-create/zap-plan, run each swap step, then mint with the output. |
remove / claim | Withdraw liquidity (partial/full) or claim fees. |
compound / rebalance | Add fees back to the position, or move to a new range. |
stake / unstake | Aerodrome: stake the position in a gauge for rewards. |
Zap uses dedicated plan endpoints: POST /v1/zap-in-contract-plans and POST /v1/zap-out-contract-plans (one transaction through the BaniZap contract); the response contains approvals, call, the minimum output and platformFee.
Bridging via the API
bash
# Rute tersedia
curl -s https://banipool.com/api/v1/bridge/routes | jq '.data[] | {symbol, fromChainRef, toChainRef}'
# Kuota (sesi wallet; Idempotency-Key wajib) → transaction + approvals
curl -s -X POST https://banipool.com/api/v1/bridge/quotes \
-H "authorization: Bearer $BANIPOOL_SESSION" -H "idempotency-key: $(uuidgen)" \
-H "content-type: application/json" \
-d '{"fromChainRef":"eip155:8453","toChainRef":"eip155:1","symbol":"USDC","amount":"5000000"}'
# Setelah transaksi dikirim: daftarkan untuk dilacak sampai completed
curl -s -X POST https://banipool.com/api/v1/bridge/transfers -H "authorization: Bearer $BANIPOOL_SESSION" \
-H "content-type: application/json" -d '{"quoteId":"<id kuota>","txHash":"0x…"}'