@tokenflight/fiat-client
v0.0.1
Published
Typed client for the @tokenflight/fiat HTTP contract — zero runtime dependencies
Readme
@tokenflight/fiat-client
Zero-dependency typed client for the standard @tokenflight/fiat HTTP contract. Works in browsers, workers, and Node ≥ 18; every import from @tokenflight/fiat is type-only, so the runtime bundle is a few KB with no dependencies.
import { createFiatClient } from "@tokenflight/fiat-client";
const fiat = createFiatClient(); // defaults to https://fiat.hyperstream.dev/v1/fiat
const { quotes, errors } = await fiat.quotes({
fiatCurrency: "USD",
fiatAmount: "100.00",
outputAsset: { chainId: 8453, address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" },
recipient: "0xYourWallet…",
});
// Pre-open the popup in the click handler's synchronous stack (popup blockers
// reject window.open after an await), then navigate it once the order lands.
const popup = window.open("about:blank", "_blank", "popup,width=480,height=720");
const order = await fiat.createOrder({ quoteId: quotes[0].quoteId });
if (order.action.type === "wrapper" && popup) popup.location = order.action.url;
else popup?.close();
const finished = await fiat.waitForOrder(order.orderId, { onOrder: (o) => render(o.progress) });
console.log(finished.status, finished.transferTxHash);quotesStream()— async-iterate provider quotes as they settle (NDJSON), so one slow provider never delays a comparison UI.- Errors are always a typed
FiatClientError(code,retryable,status); transport failures map toNETWORK_ERROR/TIMEOUT/INVALID_RESPONSE. - Point it at a self-hosted deployment with
createFiatClient({ baseUrl, basePath }).
© Khalani Labs, Ltd. All rights reserved.
