0.1.14 • Published 6 months ago

@utxoswap/swap-sdk-js v0.1.14

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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

0.1.14

6 months ago

0.1.12

7 months ago

0.1.13

7 months ago

0.1.11

9 months ago

0.1.10

10 months ago

0.1.9

10 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago