The AnyAlt SDK provides a set of powerful functions that enable you to manage the complete cross-chain swap flow. Below is an overview of each API function available within the SDK.
AnyAlt SDK Class
Constructor
new AnyAlt(apiKey: string)
Description:
Creates a new instance of the AnyAlt SDK.
Parameters:
apiKey (string): Your unique API key for authenticating requests.
Returns:
An instance of the AnyAlt SDK.
Methods
getChains
getChains(): Promise<SupportedChainsResponse>
Description:
Retrieves a list of available blockchain networks.
Description:
Calculates the optimal route for executing a cross-chain swap between a source and destination token.
Parameters:
export interface RoutesRequest {
/**
* UUID of the source token. This UUID corresponds to the token metadata stored in our db.
* @format uuid
* @example "123e4567-e89b-12d3-a456-426614174000"
*/
from: string;
/**
* UUID of the source token. This UUID corresponds to the token metadata stored in our db.
* @format uuid
* @example "987e6543-e21b-32d3-b654-526614174999"
*/
to: string;
/**
* Amount
* Amount of the source token to route. Represented as a string to maintain precision.
* @example "0.1"
*/
amount: string;
/**
* Slippage
* Maximum acceptable slippage percentage for the route. Represented as a string to maintain precision.
* @example "1.0"
*/
slippage: string;
}
Returns:
export interface BestRouteResponse {
/** UUID of the request */
requestId: string;
/** Amount of the output token */
outputAmount: string;
/**
* Array of swap routes
* @example [{"swapperId":"0","swapperLogo":"https://example.com/logo.png","swapperType":"BRIDGE","swapChainType":"INTER_CHAIN","from":{"blockchain":"ethereum","address":"0xPLACEHOLDER","symbol":"ETH","logo":"https://example.com/logo.png","blockchainLogo":"https://example.com/logo.png","decimals":18,"usdPrice":1000},"to":{"blockchain":"binance","address":"0xPLACEHOLDER","symbol":"BNB","logo":"https://example.com/logo.png","blockchainLogo":"https://example.com/logo.png","decimals":18,"usdPrice":1000},"toAmount":"100000000","fromAmount":"100000000","fromAmountMaxValue":"100000000","fromAmountMinValue":"100000000","fromAmountPrecision":"100000000","fromAmountRestrictionType":"INCLUSIVE","routes":[{"nodes":[{"from":"ETH","fromAddress":"0xPLACEHOLDER","fromBlockchain":"ethereum","fromLogo":"https://example.com/logo.png","to":"USDT","toAddress":"0xPLACEHOLDER","toBlockchain":"binance","toLogo":"https://example.com/logo.png","nodes":[{"marketId":"0","marketName":"Uniswap","percent":45}]}]}],"internalSwaps":[],"fee":[],"estimatedTimeInSeconds":100,"timeStat":null,"includesDestinationTx":false,"maxRequiredSign":1,"recommendedSlippage":null,"warnings":[]}]
*/
swaps: SwapResult[];
/**
* Indicates if the provided wallets do not include one which supports the source token's blockchain
* @example false
*/
missingWalletForSourceBlockchain: boolean;
}
export interface SwapResult {
/** Unique Id of swapper. example: PARASWAP */
swapperId: string;
/** Logo of the swapper */
swapperLogo: string;
/** Type of swapper. example: BRIDGE, DEX, AGGREGATOR */
swapperType: 'BRIDGE' | 'DEX' | 'AGGREGATOR' | 'OFF_CHAIN';
/** Type of swapping. It could be inter chain or intra chain */
swapChainType: 'INTER_CHAIN' | 'INTRA_CHAIN';
/** The source asset */
from: SwapResultAsset;
/** The destination asset */
to: SwapResultAsset;
/** Estimated input amount of this step. Can be used for previewing to user and should not be used for real computation, since it may change when the real transaction happens due to volatility of the market */
fromAmount: string;
/** Estimated output amount of this step. Can be used for previewing to user and should not be used for real computation, since it may change when the real transaction happens due to volatility of the market */
toAmount: string;
/** The internal routing of this step showing how the initial swap request will be split and executed. This can be used for previewing purpose to give the user a sense of what's going to happen. Null indicates that there is no internal mechanism and swapping is simple and straight-forward. */
routes: SwapRoute[] | null;
/** The internal swaps for this step. Used for aggregators' internal steps. */
internalSwaps: SwapResult[] | null;
/** List of fees that are taken from user in this step */
fee: SwapFee[];
/** Type of from amount restriction */
fromAmountRestrictionType: 'INCLUSIVE' | 'EXCLUSIVE';
/** The estimated time (in seconds) that this step might take, beware that this number is just an estimation and should be used only for user preview, example: 15 */
estimatedTimeInSeconds: number;
/** The minimum, avg and max estimation time for this step */
timeStat: TimeStat | null;
/** Is it required to sign a transaction on the destination chain or not */
includesDestinationTx: boolean;
/** Max number of transaction signing required by the user */
maxRequiredSign: number;
/** Recommended slippage */
recommendedSlippage: RecommendedSlippage | null;
/** List of warnings for this swap step, it's usually an empty list */
warnings: string[];
}
export interface SwapResultAsset {
/** Blockchain of the source/destination asset of this step */
blockchain: string;
/** Contract address of the source/dest asset of this step, null for native token */
address: string | null;
/** Symbol of the source/destination asset of this step, example: OSMO */
symbol: string;
/** Absolute path of the logo of the source/destination asset of this step */
logo: string;
/** Absolute path of the logo of the asset blockchain */
blockchainLogo: string;
/** Decimals of the source/destination asset of this step, example: 18 */
decimals: number;
/** USD price unit for the asset if available */
usdPrice: number | null;
}
export interface SwapRoute {
/** List of parallel paths that splitting happens */
nodes: SwapSuperNode[] | null;
}
export interface SwapSuperNode {
/** Symbol of the source asset */
from: string;
/** Contract address of source asset, null for native tokens */
fromAddress: string | null;
/** Blockchain of the source asset */
fromBlockchain: string;
/** Absolute path of logo of the source asset */
fromLogo: string;
/** Symbol of the destination asset */
to: string;
/** Contract address of destination asset, null for native tokens */
toAddress: string | null;
/** Blockchain of the destination asset */
toBlockchain: string;
/** Absolute path of logo of the destination asset */
toLogo: string;
/** List of intermediate nodes in a swap path */
nodes: SwapNode[];
}
export interface SwapNode {
/** Id of the market */
marketId: string | null;
/** Name of the market, example: Uniswap */
marketName: string;
/** Percent of the allocation to this path, example: 45 */
percent: number;
}
export interface SwapFee {
/** A display name for this fee, example: Network Fee */
name: string;
/** Type of the fee, example: FROM_SOURCE_WALLET */
expenseType: 'FROM_SOURCE_WALLET' | 'DECREASE_FROM_OUTPUT' | 'FROM_DESTINATION_WALLET';
/** Underlying asset for paying fee, example: BNB for BSC blockchain */
asset: Asset;
/** The human readable amount of fee, example: 0.004 */
amount: string;
/** Price of the fee asset */
price: number | null;
/** EVM Fee Info for the Swap Fee */
meta: EVMFeeMeta | null;
}
export interface Asset {
/** Blockchain of the asset */
blockchain: string;
/** Contract address of the asset, null for native token */
address: string | null;
/** Symbol of the asset */
symbol: string;
}
export interface EVMFeeMeta {
/**
* Type of the fee meta
* @example "EvmNetworkFeeMeta"
*/
type: string;
/** Gas limit */
gasLimit: string;
/** Gas price */
gasPrice: string;
}
export interface TimeStat {
/** The minimum duration (in seconds) that usually takes for related step */
min: number;
/** The average duration (in seconds) that usually takes for related step */
avg: number;
/** The maximum duration (in seconds) that usually takes for related step */
max: number;
}
export interface RecommendedSlippage {
/** If true, means that AnyAlt failed to compute slippage for this step. */
error: boolean;
/** The slippage amount in percent, example: 5 */
slippage: string;
}
Description:
Confirms the selected swap route and prepares the operation for execution.
Parameters:
export interface ConfirmRouteRequestDto {
/** The selected route to confirm */
selectedRoute: SelectedRoute;
/**
* Mapping of network names to wallet addresses
* @example {"BSC":"0xeae6d42093eae057e770010ffd6f4445f7956613","AVAX_CCHAIN":"0xeae6d42093eae057e770010ffd6f4445f7956613"}
*/
selectedWallets: Record<string, string>;
/**
* Destination blockchain address
* @example "0x6f33bb1763eebead07cf8815a62fcd7b30311fa3"
*/
destination: string;
/** Custom identifier for the operation */
customId?: string;
}
export interface SelectedRoute {
/**
* The unique identifier of the selected route
* @example "123e4567-e89b-12d3-a456-426614174000"
*/
requestId: string;
}
Returns:
export interface ConfirmRouteResponse {
/** Indicates if the route has been confirmed */
ok: boolean;
result: BestRouteResponse | null;
/** UUID of the operation */
operationId: string;
/** The status of each blockchain */
walletStatuses: BlockchainStatus[];
}
import { useCallback } from 'react';
const handleTransactionProgress = useCallback((progress) => {
// Update UI based on progress.status
console.log("Current progress:", progress.status);
}, []);
await anyalt.executeSwap(
operationId,
"1.0",
swaps,
handleTransactionProgress
);
This API reference provides a comprehensive overview of the functions available in the AnyAlt SDK. Using these methods, you can build a fully customized interface to manage cross-chain swaps and last-mile transactions while maintaining complete control over the user experience.