Alex-SDK
Alex-SDK is an easy-to-use library that exposes the swap functionality from alexlab.co 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:
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.
Usage
import { AlexSDK, Currency } from 'alex-sdk';
const alex = new AlexSDK();
(async () => {
const feeRate = await alex.getFeeRate(Currency.STX, Currency.ALEX);
console.log('Swap fee:', feeRate);
const router = await alex.getRoute(Currency.STX, Currency.ALEX);
console.log('Router path:', router);
const amountTo = await alex.getAmountTo(
Currency.STX,
BigInt(100 * 1e8),
Currency.ALEX
);
console.log('Amount to receive:', Number(amountTo) / 1e8);
const tx = await alex.runSwap(
stxAddress,
Currency.STX,
Currency.ALEX,
BigInt(Number(amount) * 1e8),
BigInt(0)
);
await openContractCall(tx);
const latestPrices = await alex.getLatestPrices();
console.log('Latest prices:', latestPrices);
const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
const balances = await alex.getBalances(stxAddress);
console.log('Balances:', balances);
const swappableCurrencies = await alex.fetchSwappableCurrency();
console.log('Swappable currencies:', swappableCurrencies);
const allRoutes = await alex.getAllPossibleRoutes(Currency.STX, Currency.ALEX);
console.log('All possible routes:', allRoutes);
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.
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.