### Run UTXO Swap SDK Example Application Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md These commands navigate into the example directory, install its specific dependencies, and link the locally built UTXO Swap SDK. Finally, `yarn dev` starts the development server, launching the example application for testing and demonstration purposes. ```bash $ cd example/ $ yarn $ yarn link @utxoswap/swap-sdk-js $ yarn dev ``` -------------------------------- ### Install Example Project Dependencies Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This command installs all required Node.js packages for the UTXO Swap SDK example project. It prepares the environment for building and running the demonstration application. ```bash $ yarn ``` -------------------------------- ### Build and Link UTXO Swap SDK for Local Development Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md These commands compile the TypeScript source code of the UTXO Swap SDK into JavaScript. The `yarn link` command then creates a symbolic link, allowing the SDK to be used locally by other projects, such as the provided example application, without publishing it to a registry. ```bash $ yarn build $ yarn link ``` -------------------------------- ### Install UTXO Swap SDK Package Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This command adds the official UTXO Swap SDK package to your project's dependencies. It's the first step to integrate the SDK into your application, making its functionalities available for import and use. ```bash $ yarn add @utxoswap/swap-sdk-js ``` -------------------------------- ### Configure ESLint parserOptions for Type-Aware Linting in JavaScript Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/example/README.md This snippet demonstrates how to configure the 'parserOptions' property within an ESLint configuration file. It sets the ECMAScript version, source type, and specifies paths to TypeScript configuration files ('tsconfig.json', 'tsconfig.node.json') relative to the ESLint config, enabling type-aware linting rules for TypeScript projects. ```JavaScript export default { // other rules... parserOptions: { ecmaVersion: 'latest', sourceType: 'module', project: ['./tsconfig.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, }, } ``` -------------------------------- ### Import and Initialize Core UTXO Swap SDK Components Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This TypeScript snippet demonstrates how to import essential classes like `Collector`, `Token`, `Client`, and `Pool` from the SDK. It then initializes a `Collector` for CKB on-chain data queries and a `Client` for interacting with the UTXO Swap backend service, using an API key for authentication. ```typescript import { Collector, Token, Client, Pool } from '@utxoswap/swap-sdk-js'; /// for CKB on chain query const collector = new Collector({ ckbIndexerUrl }); /// for utxo swap backend service const apiKey = "your api key" const client = new Client(false, apiKey); ``` -------------------------------- ### Instantiate a UTXO Swap Pool Object Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This snippet demonstrates the creation of a `Pool` instance, which represents a specific liquidity pool on UTXO Swap. It requires various parameters including token information, the user's CKB address, and the previously initialized `collector` and `client` instances, along with the `poolInfo` retrieved from the backend. ```typescript const pool = new Pool({ tokens, ckbAddress: address, collector, client, poolInfo, }); ``` -------------------------------- ### Execute a UTXO Swap Transaction with Exact Input Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This asynchronous function initiates an actual swap on the UTXO Swap protocol. It requires a `signTxFunc` (your transaction signing function), a `slippage` tolerance (defaulting to 0.5%), and a minimum CKB fee rate. The function returns the transaction hash upon successful execution of the swap. ```typescript const intentTxHash = await pool.swapWithExactInput( signTxFunc, // transaction sign function slippage, // default 0.5, 1-100 5000 // CKB fee rate, must equal to or greater than 5000 ); ``` -------------------------------- ### Retrieve Existing Liquidity Pools from UTXO Swap Backend Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This asynchronous TypeScript code snippet shows how to fetch a list of existing liquidity pools. It uses the initialized `client` instance to call `getPoolsByToken`, providing pagination parameters and a search key to filter the results, typically by a token's type hash. ```typescript const { list: pools } = await client.getPoolsByToken({ pageNo: 0, pageSize: 10, searchKey: "0x0000000000000000000000000000000000000000000000000000000000000000", }); ``` -------------------------------- ### Calculate Expected Output Amount and Price Impact for Swap Source: https://github.com/utxoswap/utxoswap-sdk-js/blob/main/README.md This TypeScript code uses the `Pool` instance to simulate a swap and determine the expected output amount and the associated price impact. The `calculateOutputAmountAndPriceImpactWithExactInput` method takes the desired input value and returns the calculated output, helping users understand the trade's potential outcome before execution. ```typescript const { output } = pool.current.calculateOutputAmountAndPriceImpactWithExactInput( inputValue ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.