Soheil.fi
Soheil RouterDocs
Get started

Quick start

From an API key to a confirmed swap: quote, approve, send.

Steps

  1. Get an API key. See API keys.
  2. Ask for a quote with GET /v1/quote.
  3. Approve exactly fromAmount to approvalAddress, when it is set.
  4. Send transactionRequest as it is, from the user's wallet.
  5. 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),
});
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.