# alex-sdk

> Alex-SDK is an easy-to-use library that exposes the swap functionality from [alexlab.co](https://app.alexlab.co/swap) to be integrated into any app or wallet. It enables users to perform swaps with a wide variety of supported currencies.

Latest version **3.2.1** (published 2025-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install alex-sdk
pnpm add alex-sdk
yarn add alex-sdk
bun add alex-sdk
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2025-04-24 |
| First published | 2023-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kyle Fang |
| Maintainers | zhigang1992 |

## Links

- npm: https://www.npmjs.com/package/alex-sdk
- npm.io page: https://npm.io/package/alex-sdk

## Dependencies (1)

- [clarity-codegen](https://npm.io/package/clarity-codegen.md) 1.0.0-beta.1

## Recent versions

- 3.2.1 (latest) — 2025-04-24
- 3.0.0-beta.1 (beta) — 2024-11-28
- 0.1.7 (next) — 2023-04-24
- 3.2.0 — 2025-03-18
- 3.1.0 — 2025-03-05
- 3.0.4 — 2025-02-24
- 3.0.3 — 2024-12-22
- 3.0.2 — 2024-12-22
- 3.0.1 — 2024-12-13
- 3.0.0 — 2024-12-11
- 3.0.0-beta.5 — 2024-12-11
- 3.0.0-beta.4 — 2024-12-11
- 3.0.0-beta.3 — 2024-12-11
- 3.0.0-beta.2 — 2024-12-11
- 2.2.0-beta.0 — 2024-11-28
- … 43 more at https://npm.io/package/alex-sdk/versions

## README

# Alex-SDK

Alex-SDK is an easy-to-use library that exposes the swap functionality from [alexlab.co](https://app.alexlab.co/swap) to be integrated into any app or wallet. It enables users to perform swaps with a wide variety of supported currencies.

## Installation

You can install Alex-SDK using npm:

```bash
npm install alex-sdk
```

## Documentation

For detailed API documentation, including a full list of available methods and their usage, please refer to:

[SDK API Documentation](https://alexgo-io.github.io/alex-sdk/).

## Usage

```typescript
import { AlexSDK, Currency } from 'alex-sdk';

const alex = new AlexSDK();

(async () => {
  // Get swap fee between STX and ALEX
  const feeRate = await alex.getFeeRate(Currency.STX, Currency.ALEX);
  console.log('Swap fee:', feeRate);

  // Get the router path for swapping STX to ALEX
  const router = await alex.getRoute(Currency.STX, Currency.ALEX);
  console.log('Router path:', router);

  // Get the amount of USDA that will be received when swapping 100 ALEX
  const amountTo = await alex.getAmountTo(
    Currency.STX,
    BigInt(100 * 1e8), // all decimals are multiplied by 1e8
    Currency.ALEX
  );
  console.log('Amount to receive:', Number(amountTo) / 1e8);

  // To get the transaction to broadcast
  const tx = await alex.runSwap(
    stxAddress,
    Currency.STX,
    Currency.ALEX,
    BigInt(Number(amount) * 1e8),
    BigInt(0)
  );

  // Then broadcast the transaction yourself
  await openContractCall(tx);

  // Get the latest prices for all supported currencies
  const latestPrices = await alex.getLatestPrices();
  console.log('Latest prices:', latestPrices);

  // Get balances for a specific STX address
  const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
  const balances = await alex.getBalances(stxAddress);
  console.log('Balances:', balances);

  // Fetch information about all swappable currencies
  const swappableCurrencies = await alex.fetchSwappableCurrency();
  console.log('Swappable currencies:', swappableCurrencies);
  
  // Get all possible routes for swapping currencies
  const allRoutes = await alex.getAllPossibleRoutes(Currency.STX, Currency.ALEX);
  console.log('All possible routes:', allRoutes);

  // Get way points
  const someRoute: AMMRoute = [x1, x2];
  const wayPoints = await sdk.getWayPoints(someRoute);
  console.log('Way points for the route:', wayPoints);
})();
```

There is a fully working example in the [alex-sdk-example](https://github.com/alexgo-io/alex-sdk-example).

## Contributing

Contributions to the project are welcome. Please fork the repository, make your changes, and submit a pull request. Ensure your changes follow the code style and conventions used.

---
_Source: https://npm.io/package/alex-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
