Local trading
Send a mint and an amount, get back an unsigned transaction, sign it with your own wallet and send it. Your private key never leaves your machine: the API only ever sees your public key.
No key and no account needed: anyone can trade. The fee is 0.25% of the SOL side of each trade, taken inside the transaction itself as one transfer. A Koi key works too, at the same fee. Local trading runs in Frankfurt, fra.api.koi.tools, at up to 3 requests a second on each endpoint.
What you needโ
- A Solana wallet, with its private key in base58, and enough SOL for the trade plus network fees.
- Node.js or Python, to run the examples as they are.
- No RPC. Post the signed transaction to
/api/sendand we broadcast it. Your own RPC works too.
Exampleโ
- JavaScript
- Python
import { Keypair, VersionedTransaction } from "@solana/web3.js";
import bs58 from "bs58";
const wallet = Keypair.fromSecretKey(bs58.decode("<your wallet private key, base58>"));
// 1. Build an unsigned transaction.
const res = await fetch("https://fra.api.koi.tools/api/local-trade", {
method: "POST",
headers: { "content-type": "application/json", "accept": "application/json" },
body: JSON.stringify({
action: "buy", // "buy" or "sell"
publicKey: wallet.publicKey.toBase58(),
mint: "<token mint>",
amount: 0.01, // SOL on a buy; tokens or "100%" on a sell
slippage: 10, // percent
priorityFee: 0.0001, // SOL
}),
});
const { tx } = await res.json();
// 2. Sign on your machine: the private key stays in this script.
const signed = VersionedTransaction.deserialize(Buffer.from(tx, "base64"));
signed.sign([wallet]);
// 3. Send it: we broadcast it and wait for confirmation.
const sent = await (await fetch("https://fra.api.koi.tools/api/send", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ signedTx: Buffer.from(signed.serialize()).toString("base64") }),
})).json();
console.log(sent.status, sent.explorer); // "landed" https://solscan.io/tx/โฆ
import base64, requests, base58
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction
wallet = Keypair.from_bytes(base58.b58decode("<your wallet private key, base58>"))
# 1. Build an unsigned transaction.
res = requests.post(
"https://fra.api.koi.tools/api/local-trade",
headers={"accept": "application/json"},
json={
"action": "buy", # "buy" or "sell"
"publicKey": str(wallet.pubkey()),
"mint": "<token mint>",
"amount": 0.01, # SOL on a buy; tokens or "100%" on a sell
"slippage": 10, # percent
"priorityFee": 0.0001, # SOL
},
)
raw = VersionedTransaction.from_bytes(base64.b64decode(res.json()["tx"]))
# 2. Sign on your machine: the private key stays in this script.
signed = VersionedTransaction(raw.message, [wallet])
# 3. Send it: we broadcast it and wait for confirmation.
sent = requests.post("https://fra.api.koi.tools/api/send",
json={"signedTx": base64.b64encode(bytes(signed)).decode()}).json()
print(sent["status"], sent["explorer"]) # landed https://solscan.io/tx/โฆ
Request fieldsโ
POST https://fra.api.koi.tools/api/local-trade, a JSON body. With accept: application/json the answer is JSON (below); without it, the raw transaction bytes.
| Field | Type | |
|---|---|---|
action | "buy" / "sell" | |
publicKey | string | Your wallet. It signs and pays the network fee. |
mint | string | The coin's mint. |
amount | number or string | A buy: how much SOL goes in. A sell: tokens, or a share of what the wallet holds, "100%" for all of it, "50%" for half. |
slippage | number | Percent. Default 5. |
priorityFee | number | SOL. Default about 0.0002. |
pool | string | Optional: force a venue (below). Left out, the coin is routed to wherever it trades now, migrations followed. |
poolAddress | string | For raydium_cpmm, raydium_amm_v4 and meteora_damm_v2 when we know no pool for the coin yet. |
jitoTip | number | SOL. Adds a transfer to a Jito tip account, for sending the signed transaction to a block engine yourself. |
settle | string | For a coin priced in something other than SOL (USDC, a stock, another coin): "sol" trades it with SOL in one transaction, left out it is paid in that asset. See Coins not priced in SOL. |
The answerโ
{
"tx": "AQAAAAโฆ",
"txVersion": "v0",
"blockhash": "8f3kโฆ",
"feeLamports": 25000,
"feeMint": "SOL",
"quoteMint": "So11111111111111111111111111111111111111112",
"warning": null,
"buildMs": 11.4
}
tx is the unsigned transaction in base64. feeLamports is our 0.25%, in the base units of feeMint. warning says when something about the trade deserves a look before you sign.
Sendingโ
POST https://fra.api.koi.tools/api/send broadcasts one signed transaction, so your bot needs no RPC. It only forwards transactions this API built in the last 15 minutes, unchanged: anything else is refused with not_ours. Using it is optional; a signed transaction can always go through your own RPC.
| Field | Type | |
|---|---|---|
signedTx | base64 | The signed transaction. |
wait | boolean | Default true: wait for confirmation. false answers as soon as the node accepts it. |
{ "signature": "5Kdโฆ", "status": "landed", "slot": 372114820, "explorer": "https://solscan.io/tx/5Kdโฆ" }
status is landed (confirmed), failed (it ran and failed on chain; error says why) or pending (not waited for, or not confirmed within 60 seconds). A transaction the node refuses before running it, for too little SOL, slippage or an expired blockhash, comes back as a 400 with the node's reason.
Venuesโ
pool | Venue |
|---|---|
pumpfun | pump.fun bonding curve |
pumpswap | PumpSwap, where pump.fun coins trade after graduation |
bonk, stonkfun | Raydium LaunchLab: letsbonk.fun, StonkFun and the other LaunchLab platforms |
meteora_dbc | Meteora Dynamic Bonding Curve, Bags and Moonshot among them |
raydium_cpmm | Raydium CPMM, where LaunchLab coins trade after graduation |
raydium_amm_v4 | Raydium AMM v4 |
meteora_damm_v2 | Meteora DAMM v2, where DBC coins trade after graduation |
Slippage on Meteora DBC is measured against the spot price: leave room on a large buy into a steep curve.
Coins not priced in SOLโ
Some coins are priced in USDC, a tokenised stock or another coin. Such a coin trades in that asset by default: a buy's amount is how much of it to spend, the wallet must hold it, a sell pays out in it, and the fee is taken in it (feeMint says which).
With settle: "sol" it trades with SOL instead: the same transaction swaps the SOL into that asset and back. This transaction is a v1 transaction (txVersion: "v1"), which many libraries cannot read yet: sign the message, every byte but the last 64, with your wallet's key and write the 64-byte signature into those last 64 bytes, then post it to /api/send as usual.
A coin paired with another pump.fun coin needs nothing of this: it is bought and sold with SOL in one multi-hop swap, and the answer carries route and hops.
If something goes wrongโ
The answer is { "error": "โฆ" } with a short message. The usual causes: a wrong wallet address or mint, or not enough SOL. 429 means more than 3 requests a second on that endpoint: wait a second and retry.