### Quick Start: Get a Quote Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Initialize the LayerSwapApi and get a quote for a token transfer. Ensure you replace 'your-api-key' with your actual API key. ```ts import { LayerSwapApi } from '@layerswap/sdk'; const api = new LayerSwapApi({ apiKey: 'your-api-key', }); // Get a quote const quote = await api.getQuote({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, }); console.log(quote.receive_amount); // 0.099... ``` -------------------------------- ### Install @layerswap/sdk Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Install the SDK using npm. This is the first step to integrate with the Layerswap API. ```sh npm install @layerswap/sdk ``` -------------------------------- ### Get Swaps Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md List all swaps associated with a specific address. ```APIDOC ## Get Swaps ### Description List all swaps associated with a specific address. ### Method GET ### Endpoint `/swaps` ### Parameters #### Path Parameters None #### Query Parameters - **address** (string) - Required - The address to list swaps for. #### Request Body None ### Request Example ```typescript const swaps = await api.getSwaps({ address: '0x...' }); ``` ### Response #### Success Response (200) - **swaps** (LsSwap[]) - An array of swap objects. #### Response Example ```json [ { "id": "swap-id-1", "status": "completed" }, { "id": "swap-id-2", "status": "pending" } ] ``` ``` -------------------------------- ### Get Deposit Actions Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve deposit actions required for a swap. ```APIDOC ## Get Deposit Actions ### Description Retrieve deposit actions required for a swap. ### Method GET ### Endpoint `/swap/{swapId}/deposit-actions` ### Parameters #### Path Parameters - **swapId** (string) - Required - The ID of the swap. - **sourceAddress** (string) - Required - The source address initiating the deposit. #### Query Parameters None #### Request Body None ### Request Example ```typescript const actions = await api.getDepositActions('swap-id', '0xsourceAddress'); ``` ### Response #### Success Response (200) - **depositActions** (LsDepositAction[]) - An array of deposit actions. #### Response Example ```json [ { "type": "transfer", "token": "ETH", "amount": "0.1", "to": "0x..." } ] ``` ``` -------------------------------- ### Get Sources Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Find available source networks and tokens for a given destination. ```APIDOC ## Get Sources ### Description Find available source networks and tokens for a given destination. ### Method GET ### Endpoint `/sources` ### Parameters #### Path Parameters None #### Query Parameters - **destinationNetwork** (string) - Required - The destination network ID. - **destinationToken** (string) - Required - The destination token symbol. ### Request Example ```typescript const sources = await api.getSources({ destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', }); ``` ### Response #### Success Response (200) - **sources** (LsRoute[]) - An array of available source routes. #### Response Example ```json [ { "network": { "id": "ETHEREUM_MAINNET", "name": "Ethereum Mainnet", "type": "evm", "layer": 1 }, "token": { "symbol": "ETH", "address": "0x..." } } ] ``` ``` -------------------------------- ### Swap Lifecycle: Get Deposit Actions Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Fetch the deposit actions required for a specific swap and source address. ```ts // Get deposit actions const actions = await api.getDepositActions('swap-id', '0xsourceAddress'); ``` -------------------------------- ### Get Swap Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve details of a specific swap by its ID. ```APIDOC ## Get Swap ### Description Retrieve details of a specific swap by its ID. ### Method GET ### Endpoint `/swap/{swapId}` ### Parameters #### Path Parameters - **swapId** (string) - Required - The ID of the swap. #### Query Parameters None #### Request Body None ### Request Example ```typescript const details = await api.getSwap('swap-id'); ``` ### Response #### Success Response (200) - **swapDetails** (LsSwap) - The detailed swap object. #### Response Example ```json { "id": "swap-id", "status": "completed", "source_network": "ETHEREUM_MAINNET", "destination_network": "STARKNET_MAINNET" } ``` ``` -------------------------------- ### Get Quote Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Get a transfer quote including receive amount and fees. ```APIDOC ## Get Quote ### Description Get a transfer quote including receive amount and fees. ### Method GET ### Endpoint `/quote` ### Parameters #### Path Parameters None #### Query Parameters - **sourceNetwork** (string) - Required - The source network ID. - **sourceToken** (string) - Required - The source token symbol. - **destinationNetwork** (string) - Required - The destination network ID. - **destinationToken** (string) - Required - The destination token symbol. - **amount** (number) - Required - The amount to transfer. ### Request Example ```typescript const quote = await api.getQuote({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, }); console.log(quote.receive_amount, quote.total_fee); ``` ### Response #### Success Response (200) - **receive_amount** (number) - The amount expected to be received on the destination network. - **total_fee** (number) - The total estimated fee for the transfer. #### Response Example ```json { "receive_amount": 0.099, "total_fee": 0.001 } ``` ``` -------------------------------- ### Get Detailed Quote Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Get a detailed transfer quote including routing information. ```APIDOC ## Get Detailed Quote ### Description Get a detailed transfer quote including routing information. ### Method GET ### Endpoint `/quote/detailed` ### Parameters #### Path Parameters None #### Query Parameters - **sourceNetwork** (string) - Required - The source network ID. - **sourceToken** (string) - Required - The source token symbol. - **destinationNetwork** (string) - Required - The destination network ID. - **destinationToken** (string) - Required - The destination token symbol. - **amount** (number) - Required - The amount to transfer. ### Request Example ```typescript const detailed = await api.getDetailedQuote({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, }); ``` ### Response #### Success Response (200) - **detailedQuote** (LsDetailedQuote) - A detailed quote object including routing information. #### Response Example ```json { "receive_amount": 0.099, "total_fee": 0.001, "route": { "bridge": { "name": "MyBridge", "type": "bridge" }, " মাধ্যমে": { "name": "MyAggregator", "type": "aggregator" } } } ``` ``` -------------------------------- ### Route Discovery: Get Sources Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Find available source networks and tokens for a given destination network and token. ```ts // Get source networks/tokens for a destination const sources = await api.getSources({ destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', }); ``` -------------------------------- ### Get Destinations Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Find available destination networks and tokens for a given source. ```APIDOC ## Get Destinations ### Description Find available destination networks and tokens for a given source. ### Method GET ### Endpoint `/destinations` ### Parameters #### Path Parameters None #### Query Parameters - **sourceNetwork** (string) - Required - The source network ID. - **sourceToken** (string) - Required - The source token symbol. ### Request Example ```typescript const destinations = await api.getDestinations({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', }); ``` ### Response #### Success Response (200) - **destinations** (LsRoute[]) - An array of available destination routes. #### Response Example ```json [ { "network": { "id": "STARKNET_MAINNET", "name": "Starknet Mainnet", "type": "starknet", "layer": 2 }, "token": { "symbol": "ETH", "address": "0x..." } } ] ``` ``` -------------------------------- ### Get Limits Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve transfer limits for a given route and amount. ```APIDOC ## Get Limits ### Description Retrieve transfer limits for a given route and amount. ### Method GET ### Endpoint `/limits` ### Parameters #### Path Parameters None #### Query Parameters - **sourceNetwork** (string) - Required - The source network ID. - **sourceToken** (string) - Required - The source token symbol. - **destinationNetwork** (string) - Required - The destination network ID. - **destinationToken** (string) - Required - The destination token symbol. - **amount** (number) - Required - The amount to transfer. ### Request Example ```typescript const limits = await api.getLimits({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 1, }); console.log(limits.min_amount, limits.max_amount); ``` ### Response #### Success Response (200) - **min_amount** (number) - The minimum transferrable amount. - **max_amount** (number) - The maximum transferrable amount. #### Response Example ```json { "min_amount": 0.001, "max_amount": 10 } ``` ``` -------------------------------- ### Swap Lifecycle: Get Swap Details Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve the details of a specific swap using its unique ID. ```ts // Get swap details const details = await api.getSwap('swap-id'); ``` -------------------------------- ### Get Swap By Transaction Hash Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve swap details using a transaction hash. ```APIDOC ## Get Swap By Transaction Hash ### Description Retrieve swap details using a transaction hash. ### Method GET ### Endpoint `/swap/by-transaction-hash/{transactionHash}` ### Parameters #### Path Parameters - **transactionHash** (string) - Required - The transaction hash. #### Query Parameters None #### Request Body None ### Request Example ```typescript const byTx = await api.getSwapByTransactionHash('0x...'); ``` ### Response #### Success Response (200) - **swapDetails** (LsSwap) - The detailed swap object. #### Response Example ```json { "id": "swap-id", "status": "completed", "source_network": "ETHEREUM_MAINNET", "destination_network": "STARKNET_MAINNET" } ``` ``` -------------------------------- ### Get Networks Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve a list of all available networks or filter by network types. ```APIDOC ## Get Networks ### Description Retrieve a list of all available networks or filter by network types. ### Method GET ### Endpoint `/networks` ### Parameters #### Path Parameters None #### Query Parameters - **networkTypes** (string[]) - Optional - Filter networks by type (e.g., ['evm']). ### Request Example ```typescript // Get all available networks const networks = await api.getNetworks(); const evmNetworks = await api.getNetworks({ networkTypes: ['evm'] }); ``` ### Response #### Success Response (200) - **networks** (LsNetwork[]) - An array of network objects. #### Response Example ```json [ { "id": "ETHEREUM_MAINNET", "name": "Ethereum Mainnet", "type": "evm", "layer": 1 } ] ``` ``` -------------------------------- ### Route Discovery: Get Destinations Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Find available destination networks and tokens for a given source network and token. ```ts // Get destination networks/tokens for a source const destinations = await api.getDestinations({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', }); ``` -------------------------------- ### Get Transaction Status Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Check the status of a transaction on a specific network. ```APIDOC ## Get Transaction Status ### Description Check the status of a transaction on a specific network. ### Method GET ### Endpoint `/status/transaction` ### Parameters #### Path Parameters None #### Query Parameters - **network** (string) - Required - The network ID. - **transactionId** (string) - Required - The transaction ID. #### Request Body None ### Request Example ```typescript const status = await api.getTransactionStatus({ network: 'ETHEREUM_MAINNET', transactionId: '0x...', }); ``` ### Response #### Success Response (200) - **transactionStatus** (LsTransactionStatus) - The status of the transaction. #### Response Example ```json { "status": "confirmed", "block_number": 1234567 } ``` ``` -------------------------------- ### Route Discovery: Get Networks Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Fetch all available networks or filter them by network type (e.g., 'evm'). ```ts // Get all available networks const networks = await api.getNetworks(); const evmNetworks = await api.getNetworks({ networkTypes: ['evm'] }); ``` -------------------------------- ### Swap Lifecycle: Get Swap by Transaction Hash Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Find a swap associated with a given transaction hash. ```ts // Get swap by transaction hash const byTx = await api.getSwapByTransactionHash('0x...'); ``` -------------------------------- ### Quotes & Limits: Get Detailed Quote Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Obtain a detailed quote for a transfer, including routing information. ```ts // Get detailed quote with routing info const detailed = await api.getDetailedQuote({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, }); ``` -------------------------------- ### Quotes & Limits: Get Transfer Limits Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve the minimum and maximum transfer amounts for a given token pair between two networks. ```ts // Get transfer limits const limits = await api.getLimits({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 1, }); console.log(limits.min_amount, limits.max_amount); ``` -------------------------------- ### Configuration Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Initialize the LayerSwapApi client with an API key and an optional base URL. ```APIDOC ## Configuration ### Description Initialize the LayerSwapApi client with an API key and an optional base URL. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { LayerSwapApi } from '@layerswap/sdk'; const api = new LayerSwapApi({ apiKey: 'your-api-key', // required baseUrl: 'https://api.layerswap.io', // optional, default shown }); ``` ### Response None ``` -------------------------------- ### Create Swap Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Initiate a new swap transaction. ```APIDOC ## Create Swap ### Description Initiate a new swap transaction. ### Method POST ### Endpoint `/swap` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **sourceNetwork** (string) - Required - The source network ID. - **sourceToken** (string) - Required - The source token symbol. - **destinationNetwork** (string) - Required - The destination network ID. - **destinationToken** (string) - Required - The destination token symbol. - **amount** (number) - Required - The amount to transfer. - **destinationAddress** (string) - Required - The recipient's address on the destination network. ### Request Example ```typescript const swap = await api.createSwap({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, destinationAddress: '0x...', }); console.log(swap.swap.id, swap.deposit_actions); ``` ### Response #### Success Response (200) - **swap** (LsSwap) - The created swap object. - **deposit_actions** (LsDepositAction[]) - Actions required for the deposit. #### Response Example ```json { "swap": { "id": "swap-id", "status": "pending" }, "deposit_actions": [ { "type": "transfer", "token": "ETH", "amount": "0.1", "to": "0x..." } ] } ``` ``` -------------------------------- ### Swap Lifecycle: Create Swap Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Initiate a new swap by providing transfer details and the destination address. The response includes the swap ID and deposit actions. ```ts // Create a swap const swap = await api.createSwap({ sourceNetwork: 'ETHEREUM_MAINNET', sourceToken: 'ETH', destinationNetwork: 'STARKNET_MAINNET', destinationToken: 'ETH', amount: 0.1, destinationAddress: '0x...', }); console.log(swap.swap.id, swap.deposit_actions); ``` -------------------------------- ### API Configuration Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Configure the LayerSwapApi instance with your API key and optionally a custom base URL. The default URL is used if none is provided. ```ts const api = new LayerSwapApi({ apiKey: 'your-api-key', // required baseUrl: 'https://api.layerswap.io', // optional, default shown }); ``` -------------------------------- ### Speed Up Deposit Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Expedite the detection of a deposit for a swap. ```APIDOC ## Speed Up Deposit ### Description Expedite the detection of a deposit for a swap. ### Method POST ### Endpoint `/swap/{swapId}/speed-up-deposit` ### Parameters #### Path Parameters - **swapId** (string) - Required - The ID of the swap. - **transactionHash** (string) - Required - The hash of the deposit transaction. #### Query Parameters None #### Request Body None ### Request Example ```typescript await api.speedUpDeposit('swap-id', '0xtransactionHash'); ``` ### Response #### Success Response (200) No content. #### Response Example None ``` -------------------------------- ### Swap Lifecycle: Speed Up Deposit Detection Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Manually trigger or speed up the detection of a deposit for a swap using the transaction hash. ```ts // Speed up deposit detection await api.speedUpDeposit('swap-id', '0xtransactionHash'); ``` -------------------------------- ### Swap Lifecycle: List Swaps Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Retrieve a list of swaps associated with a specific address. ```ts // List swaps for an address const swaps = await api.getSwaps({ address: '0x...' }); ``` -------------------------------- ### Error Handling: Catch LayerSwapApiError Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Implement try-catch blocks to handle potential LayerSwapApiError exceptions. Inspect properties like statusCode, errorCode, and message for details. ```ts import { LayerSwapApi, LayerSwapApiError } from '@layerswap/sdk'; try { await api.getQuote({ /* ... */ }); } catch (err) { if (err instanceof LayerSwapApiError) { console.log(err.statusCode); // 400, 403, 404, etc. console.log(err.errorCode); // e.g. "BAD_REQUEST" console.log(err.message); } } ``` -------------------------------- ### Importing Types Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Import and utilize the various TypeScript types exported by the SDK for enhanced type safety in your application. ```ts import type { LsNetwork, LsToken, LsRoute, LsQuote, LsSwap, LsSwapResponse, LsDepositAction, LsLimits, LsDetailedQuote, LsTransactionStatus, LayerSwapQuoteRequest, LayerSwapCreateRequest, } from '@layerswap/sdk'; ``` -------------------------------- ### Health Check Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Perform a health check on the Layerswap API. ```APIDOC ## Health Check ### Description Perform a health check on the Layerswap API. ### Method GET ### Endpoint `/health` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript await api.health(); ``` ### Response #### Success Response (200) API is healthy. #### Response Example None ``` -------------------------------- ### Status: Transaction Status Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Check the status of a transaction on a specific network using its transaction ID. ```ts // Transaction status const status = await api.getTransactionStatus({ network: 'ETHEREUM_MAINNET', transactionId: '0x...', }); ``` -------------------------------- ### Status: Health Check Source: https://github.com/layerswap/layerswap-sdk/blob/main/README.md Perform a health check on the Layerswap API to ensure it is operational. ```ts // Health check await api.health(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.