bch-dex-lib
v1.4.1
Published
An npm JavaScript library for browser and node.js that incorporates the SWaP protocol used by bch-dex.
Downloads
21
Maintainers
Readme
bch-dex-lib
This is a library for use in both browser and node.js JavaScript applications. It incorporates the basic SWaP protocol used by bch-dex.
The purpose of this library is build a web and Android app that can let Takers purchase tokens using the bch-dex protocol. Makers still still need to run the bch-dex back end to make Offers and accept Counter-Offers. But an app using this library allows Takers to issue a Counter Offer without needing to run back end software.
This library depends on minimal-slp-wallet and p2wdb. Both of these libraries must be instantiated and passed in as arguments when instantiating this library.
Installation
npm install --save-exact bch-dex-lib
Usage
async function start() {
try {
// Global npm libraries
const BchWallet = require('minimal-slp-wallet/index')
const { Read, Write } = require('p2wdb/index')
// Customize the two variables below for your own test. The mnemonic
// should control about $0.20 USD of BCH. The p2wdbHash should be for a
// valid Offer in the market.
const mnemonic = 'gaze result fortune pulse jeans lucky tape build maximum puppy urban size'
const p2wdbHash = 'zdpuAvWMYm7bfHTxbNwsWYmrkK3cnhtH2MzQ7QS74uYbkM3ja'
// Instantiate dependencies
const wallet = new BchWallet(mnemonic, { interface: 'consumer-api' })
await wallet.walletInfoPromise
const p2wdbRead = new Read()
const p2wdbWrite = new Write({ wif: wallet.walletInfo.privateKey, interface: 'consumer-api' })
// Instantiate the Take library.
const take = new Take({ wallet, p2wdbRead, p2wdbWrite })
// Generate a Counter Offer to take the other side of the trade expressed in the Offer.
const hash = await this.p2wdbWrite.postEntry(counterOfferData, offerData.appId)
console.log(`Counter Offer generated with P2WDB entry ${hash}`)
} catch(err) {
console.error(err)
}
}
start()
Donate
This open source software is developed and maintained by the Permissionless Software Foundation. If this library provides value to you, please consider making a donation to support the PSF developers: