GithubHelp home page GithubHelp logo

ckb-dex-sdk's Introduction

CKB DEX SDK

CI NPM

CKB DEX SDK is a comprehensive web development kit, which helps developers interact with the CKB DEX contract in JavaScript/TypeScript environments.

The SDK provides methods for making orders, taking orders, and canceling orders. Developers can use common lock scripts, such as official secp256k1/blake160 lock, JoyID lock, etc., to interact with the CKB DEX contract.

You can use the DEX to swap fungible tokens(SUDT, XUDT, etc.) and non-fungible tokens(Spore, mNFT, etc.) with CKB native asset and JoyID lock is recommended to hold and swap CKB assets.

You can build the maker transactions to transfer FT or NFT assets to DEX lock script whose args contains owner address, price(based on CKB native asset), setup, etc. Anyone can build a taker transaction, as long as the price required in the DEX lock args is met. You can cancel the maker transactions at any time before the taker transactions are executed.

Installation

$ npm i @nervina-labs/ckb-dex
# or
$ yarn add @nervina-labs/ckb-dex
# or
$ pnpm add @nervina-labs/ckb-dex

Development

Connect the JoyID Wallet

You can connect JoyID wallet using @joyid/ckb SDK connect function and then you can get the ConnectResponseData to build maker and taker transactions later.

Build and Sign transactions

You can use buildMakerTx, buildCancelTx and buildTakerTx methods to place, cancel and take orders with the ConnectResponseData and the methods will generate CKB raw transaction for you to be signed later.

You must set the asset type(CKBAsset) when calling buildXXXTx methods and the CKBAsset is defined as follows:

export enum CKBAsset {
  XUDT,
  SUDT,
  SPORE,
  MNFT,
}

The examples demonstrate how to build FT and NFT maker, taker transactions with JoyID lock and the local test private keys are for simplicity, please DON'T use the local private keys in your production DApp.

You can call the signRawTransaction method to sign the raw tx with JoyID wallet through @joyid/ckb SDK, and you can send the signed transaction through CKB RPC.

ckb-dex-sdk's People

Contributors

duanyytop avatar tianlitao avatar coocoode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.