Skip to content
TypeScript SDK

LCX Liberty. American DeFi. Your keys. Your assets. Your control.

SDKs & tools

TypeScript SDK

One npm package for the whole API: swaps, cross-chain, tokens, prices and your key. Typed end to end, and it never touches a private key.

Install

bash
npm i lcx-liberty-sdk

The current release is 1.4.0, published on 24 October 2026; Versions, below, says what each release changed. It is an ES module with type declarations and no dependencies, for Node 18 or newer, Deno, Bun, Workers or any bundler. From CommonJS, load it with await import("lcx-liberty-sdk"): a plain require throws a message saying so.

The client

One client, seven namespaces. Each is a thin wrapper over the endpoints documented in the API reference, so anything true there is true here.

ts
import { LibertyDex } from "lcx-liberty-sdk";

const lcx = new LibertyDex({ apiKey: process.env.LCX_API_KEY });
NamespaceWhat it covers
lcx.swapPrice, build and submit a same-chain swap.
lcx.crossChainQuote across chains, and follow a transfer.
lcx.multiThe multi token swap: price and build a bundle, on one chain or across two.
lcx.tokensThe token registry, and what we vouch for.
lcx.pricesUSD prices: one token, a batch, or a past day.
lcx.chainsSupported chains and index freshness.
lcx.accountYour key: plan, quota and usage.
Pass your apiKey when you create the client; it talks to https://swap-api.lcx.com. Without a key every call is refused with 401 API_KEY_REQUIRED.

A swap, end to end

execute is quote and build in one call. It hands back the quote it priced and the transaction that matches it, so nothing can sign a route it was not shown.

ts
const { quote, transaction } = await lcx.swap.execute({
  chainId: 1,
  tokenIn:  "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
  tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
  amountIn: "1000000000000000000", // base units; or amount: "1"
  taker: userAddress,
  slippageBps: 50,
});

console.log(quote.output.amount, "USDC, floor", quote.output.minimumAmount);

// { to, data, value } — hand it to whatever holds the keys.
await wallet.sendTransaction(transaction);
The SDK never sees a private key and never signs. It returns calldata; signing stays with the wallet, which is the same boundary the product itself keeps.

Approvals

Selling an ERC-20 needs an allowance for the router first. Ask before you spend gas on one: required is false when the allowance already covers the trade.

ts
const { required, spender } = await lcx.swap.allowance({
  chainId: 1,
  token: WETH,
  taker: userAddress,
  amount: quote.input.amount, // raw units, not decimal
});

The chain's native coin needs no approval. See Approvals in Core concepts for the permit path and what a router upgrade means for an existing allowance.

Errors

Every failure arrives as a LibertyError carrying the API's own machine code, so a caller branches on the code rather than matching on a message that is free to change.

ts
import { LibertyError } from "lcx-liberty-sdk";

try {
  await lcx.swap.execute(params);
} catch (e) {
  if (e instanceof LibertyError) {
    // e.code   — "no_route", "RATE_LIMITED", "price_moved", ...
    // e.status — the HTTP status
    // e.details — whatever the endpoint attached
  }
}

The codes are the ones listed under Errors in Core concepts; the SDK adds none of its own.

Versions

Upgrading changes nothing in a call. Every method takes a plain chainId, and the router a swap goes through (spender and to) always comes from the API, never from the package, so code that never hardcoded an address keeps working.

VersionPublishedWhat changed
1.4.024 Oct 2026World Chain joins the chain list, on router 2 like the other new chains. Its gas coin is ether.
1.3.019 Oct 2026Unichain, Monad, HyperEVM and Arc join the chain list. On Arc, USDC is the gas coin: name it by its contract, not the native sentinel. On HyperEVM a swap takes at most three routes, and a bundle too wide for a block is refused when quoted.
1.2.012 Oct 2026BNB Chain, Polygon, Avalanche and Robinhood Chain join the chain list. Amounts go in base units (amountIn); decimals is optional, and checked when sent. Every call needs an API key.
1.1.024 Sep 2026lcx.multi: the multi token swap, on one chain or across two.
1.0.0 to 1.0.29 and 10 Sep 2026The first release, then README corrections to the router address.