Get started
Quick start
From an API key to a confirmed swap: quote, approve, send.
Steps
- Get an API key. See API keys.
- Ask for a quote with
GET /v1/quote. - Approve exactly
fromAmounttoapprovalAddress, when it is set. - Send
transactionRequestas it is, from the user's wallet. - Follow it with
GET /v1/status, or just read the receipt.
The code
// 1. Quote (on your server: keep the key there)
const params = new URLSearchParams({
fromChainId: "8453", toChainId: "8453",
fromToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
toToken: "0x0000000000000000000000000000000000000000", // ETH
fromAmount: "100000000", // 100 USDC (6 decimals)
fromAddress: user, slippageBps: "50",
});
const q = await fetch(`https://api.soheil.fi/v1/quote?${params}`, { headers: { "x-api-key": process.env.SOHEIL_ROUTER_KEY } })
.then((r) => r.json());
if (q.error) throw new Error(q.error.message);
// 2. Approve exactly fromAmount to our contract (skipped for the coin)
if (q.approvalAddress) {
await wallet.writeContract({ address: q.fromToken, abi: erc20Abi, functionName: "approve",
args: [q.approvalAddress, BigInt(q.fromAmount)] });
}
// 3. Send the transaction as it is
const hash = await wallet.sendTransaction({
to: q.transactionRequest.to, data: q.transactionRequest.data, value: BigInt(q.transactionRequest.value),
});// 1. Quote (on your server: keep the key there)
const params = new URLSearchParams({
fromChainId: "8453", toChainId: "8453",
fromToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
toToken: "0x0000000000000000000000000000000000000000", // ETH
fromAmount: "100000000", // 100 USDC (6 decimals)
fromAddress: user, slippageBps: "50",
});
const q = await fetch(`https://api.soheil.fi/v1/quote?${params}`, { headers: { "x-api-key": process.env.SOHEIL_ROUTER_KEY } })
.then((r) => r.json());
if (q.error) throw new Error(q.error.message);
// 2. Approve exactly fromAmount to our contract (skipped for the coin)
if (q.approvalAddress) {
await wallet.writeContract({ address: q.fromToken, abi: erc20Abi, functionName: "approve",
args: [q.approvalAddress, BigInt(q.fromAmount)] });
}
// 3. Send the transaction as it is
const hash = await wallet.sendTransaction({
to: q.transactionRequest.to, data: q.transactionRequest.data, value: BigInt(q.transactionRequest.value),
});curl "https://api.soheil.fi/v1/quote?fromChainId=8453&toChainId=8453\
&fromToken=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\
&toToken=0x0000000000000000000000000000000000000000\
&fromAmount=100000000&fromAddress=0xYourUser&slippageBps=50" \
-H "x-api-key: sk_xxxxxxxx_…"Keep the key on your serverThe API allows calls from browsers, but a key in a public page can be read by anyone. Call us from your backend.