docs: fix code example issues in README

- Add missing AMMRoute import
- Move stxAddress declaration before its usage
- Add missing 'amount' variable declaration
- Fix 'sdk' -> 'alex' variable name consistency
- Fix undefined x1, x2 variables in route example
- Use allRoutes[0] as example route instead
This commit is contained in:
phessophissy
2025-12-13 08:17:32 +01:00
committed by Kyle
parent 9c26d12f36
commit 4c7e1bd016

View File

@@ -19,11 +19,14 @@ For detailed API documentation, including a full list of available methods and t
## Usage ## Usage
```typescript ```typescript
import { AlexSDK, Currency } from 'alex-sdk'; import { AlexSDK, Currency, AMMRoute } from 'alex-sdk';
const alex = new AlexSDK(); const alex = new AlexSDK();
(async () => { (async () => {
// Define your STX address
const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
// Get swap fee between STX and ALEX // Get swap fee between STX and ALEX
const feeRate = await alex.getFeeRate(Currency.STX, Currency.ALEX); const feeRate = await alex.getFeeRate(Currency.STX, Currency.ALEX);
console.log('Swap fee:', feeRate); console.log('Swap fee:', feeRate);
@@ -41,6 +44,7 @@ const alex = new AlexSDK();
console.log('Amount to receive:', Number(amountTo) / 1e8); console.log('Amount to receive:', Number(amountTo) / 1e8);
// To get the transaction to broadcast // To get the transaction to broadcast
const amount = 100; // Amount to swap
const tx = await alex.runSwap( const tx = await alex.runSwap(
stxAddress, stxAddress,
Currency.STX, Currency.STX,
@@ -56,8 +60,7 @@ const alex = new AlexSDK();
const latestPrices = await alex.getLatestPrices(); const latestPrices = await alex.getLatestPrices();
console.log('Latest prices:', latestPrices); console.log('Latest prices:', latestPrices);
// Get balances for a specific STX address // Get balances for the STX address
const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
const balances = await alex.getBalances(stxAddress); const balances = await alex.getBalances(stxAddress);
console.log('Balances:', balances); console.log('Balances:', balances);
@@ -69,9 +72,9 @@ const alex = new AlexSDK();
const allRoutes = await alex.getAllPossibleRoutes(Currency.STX, Currency.ALEX); const allRoutes = await alex.getAllPossibleRoutes(Currency.STX, Currency.ALEX);
console.log('All possible routes:', allRoutes); console.log('All possible routes:', allRoutes);
// Get way points // Get way points for a route
const someRoute: AMMRoute = [x1, x2]; const someRoute: AMMRoute = allRoutes[0]; // Use the first available route
const wayPoints = await sdk.getWayPoints(someRoute); const wayPoints = await alex.getWayPoints(someRoute);
console.log('Way points for the route:', wayPoints); console.log('Way points for the route:', wayPoints);
})(); })();
``` ```