# Velar SDK

The Velar SDK is a powerful toolkit that enables seamless integration with the Velar Protocol, allowing developers to implement token swaps, manage liquidity, and interact with the Velar DEX ecosystem. This SDK provides a robust set of tools for building decentralized applications on the Stacks blockchain.

### Installation

```bash
npm i @velarprotocol/velar-sdk
```

### Available Versions

#### [Velar SDK 0.7.0-beta \[Latest\]](/velar/developers/velar-sdk/velar-sdk-0.7.0-beta-latest.md)

The latest version introduces significant improvements and changes:

* Added support for all VELAR DEX listed tokens
* Direct token contract address support in SwapConfig
* Enhanced AmountOutResponse with detailed path information
* Simplified API with removal of SwapType requirement
* Removed support for `swapTokensForExactTokens`

#### [Velar SDK 0.6.9](/velar/developers/velar-sdk/velar-sdk-0.6.9.md)

Stable release with core functionality:

* Support for token swapping operations
* Implementation of `swapTokensForExactTokens`
* Includes bug fix for `assetName` in swap operations
* Uses SwapType enum for different swap operations

### Key Features

* **Token Swapping**: Execute token swaps with optimal routing
* **Price Computation**: Calculate swap amounts with slippage protection
* **Pair Management**: Query available trading pairs
* **Multi-hop Routing**: Support for complex swap paths
* **Contract Integration**: Seamless integration with Stacks blockchain

### Core Components

The SDK is built around several key interfaces and classes:

#### VelarSDK Class

The main entry point for interacting with the protocol:

```typescript
export declare class VelarSDK {
  getPairs(symbol: string): Promise<Array<string>>;
  getSwapInstance(args: SwapConfig): SwapService;
}
```

#### SwapService

Handles all swap-related operations:

```typescript
export declare class SwapService {
  constructor(args: SwapConfig);
  swap(args: SwapPayload): Promise<SwapResponse>;
  getComputedAmount(args: ComputedAmountPayload): Promise<AmountOutResponse>;
}
```

### Getting Started

1. Initialize the SDK:

```typescript
import { VelarSDK } from '@velarprotocol/velar-sdk';
const sdk = new VelarSDK();
```

2. Create a swap instance:

```typescript
const swapInstance = await sdk.getSwapInstance({
  account: userAddress,
  inToken: inputToken,  // Token Symbol or Contract Address
  outToken: outputToken // Token Symbol or Contract Address
});
```

3. Execute operations:

```typescript
// Get computed amount
const amountOut = await swapInstance.getComputedAmount({
  amount: 10,
  slippage: 0.5 // optional
});

// Perform swap
const swapOptions = await swapInstance.swap({
  amount: 10
});
```

### Token Support

The SDK supports a wide range of tokens on the Velar DEX, including:

* Core tokens: STX, VELAR, aeUSDC, aBTC
* Ecosystem tokens: SOME, ROCK, MICK, WELSH, LEO
* Staked variants: stSTX, sODIN, sROO, sWELSH
* And many more

For the latest list of supported tokens and their trading pairs, you can use the `getPairs` method or check the official token list at: <https://sdk-beta.velar.network/tokens/symbols>

### Migration Guide

When upgrading from 0.6.9 to 0.7.0-beta:

1. Remove all `SwapType` references
2. Update `getComputedAmount` implementation to handle new response type
3. Remove any `swapTokensForExactTokens` implementations
4. Update token inputs to optionally use contract addresses

### Best Practices

* Always implement proper error handling
* Use slippage protection for better trade execution
* Test with small amounts before large transactions
* Keep the SDK updated to the latest stable version
* Monitor transaction status using provided callbacks

### Support

For technical support, bug reports, or feature requests, please join our community on [Telegram](https://t.me/velarofficial) or [Discord](https://discord.gg/velarbtc). Our documentation is regularly updated to help you make the most of the Velar SDK.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.velar.com/velar/developers/velar-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
