@utxoswap/swap-sdk-js
TypeScript icon, indicating that this package has built-in type declarations

0.1.11 • Public • Published

Logo

UTXO Swap SDK

Preview

This project is still under active development, and we are looking forward to your feedback. View demo page here.

Using Example

Install packages:

$ yarn 

Build SDK:

$ yarn build
$ yarn link

Run example:

$ cd example/ 
$ yarn
$ yarn link @utxoswap/swap-sdk-js
$ yarn dev

Usage

Install packages:

$ yarn add @utxoswap/swap-sdk-js

Once the package is installed, you can import the library using import or require approach:

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);

/// get existed pools
const { list: pools } = await client.getPoolsByToken({
  pageNo: 0,
  pageSize: 10,
  searchKey: "0x0000000000000000000000000000000000000000000000000000000000000000",
});

/// pool instance
const pool = new Pool({
  tokens,
  ckbAddress: address,
  collector,
  client,
  poolInfo,
});

/// calculate output amount
const { output } = pool.current.calculateOutputAmountAndPriceImpactWithExactInput(
  inputValue
);

/// swap use your own sign function like ccc.signer
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
);

Example

You can find react example here

Readme

Keywords

none

Package Sidebar

Install

npm i @utxoswap/swap-sdk-js

Weekly Downloads

14

Version

0.1.11

License

MIT

Unpacked Size

516 kB

Total Files

47

Last publish

Collaborators

  • lx70770