Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coinswitch

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coinswitch

Coinswitch.co API javascript client

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

coinswitch NPM Version node Dependency Status JavaScript Style Guide

Browser and Node.js Coinswitch.co API client

Easily exchange assets with few lines of code.

Install

npm install --save coinswitch

Usage

const Coinswitch = require('coinswitch')

;(async () => {

  const cs = new Coinswitch({
    apiKey: '<YOUR API KEY>',
    userIP: '1.1.1.1'
  })

  const coinsList = await cs.getCoins()  
  console.log(coinsList)
  /*
  [
    {
        "symbol": "btc",
        "name": "Bitcoin",
        "isActive": true
    },
    {
        "symbol": "ltc",
        "name": "Litecoin",
        "isActive": true
    },
    {
        "symbol": "bch",
        "name": "Bitcoin Cash",
        "isActive": true
    },
  	...
  ]
  */
})()

Make an exchange order

const cs = new Coinswitch({
  apiKey: '<YOUR API KEY>',
  userIP: '1.1.1.1'
})

const {
  offerReferenceId,
  depositCoinAmount,
  destinationCoinAmount
} = await cs.generateOffer('btc', 'ltc', 0.03)

const {
  orderId,
  exchangeAddress: { address }
} = await cs.makeOrder({
  depositCoin: 'btc',
  destinationCoin: 'ltc',
  depositCoinAmount,
  offerReferenceId,
  userReferenceId: 'test-user',
  destinationAddress: { address: 'LXdmzmqSALB1DbJyA43b6prQCXKn1J6SdV' },
  refundAddress: { address: '16iL2ZM4CfeiH3CrtrNjGVgR6ja2p5AFec' }
})

console.log(`
=========
Order ID: ${orderId}
Deposit: BTC (${depositCoinAmount})
Receive: LTC (${destinationCoinAmount})
Exchange Address: ${address}
=========
`)

NB: Addresses must be specified as a JS Object like {address: "...", tag: "..."}

Methods

Get your api-key from the coinswitch API page.

  • new CoinSwitch(<Object>): The class constructor requires an Object like { apiKey: "...", userIP: "..."}.
Method NameReturnDescription
.version()StringReturn API version being used
.getCoins()ArrayGet list of supported coins as obj {symbol, name, isActive}
.isCoinActive(<symbol>)BooleanGiven a symbol (ex. btc) return true/false wether the coin is active or not
.getDestinationCoins(<symbol>)ArrayReturn list of available destination coins for the one provided
.getDepositCoins(<symbol>)ArrayReturn list of depositable coins for the one provided
.getExchangeLimit(<symbol>, <symbol>)ObjectGet exchange limits for a depositCoin and destinationCoin
.generateOffer(<symbol>, <symbol>, <number>)ObjectGenerate an exchange offer for a coin pair
.makeOrder(<object>*)ObjectCreates a new tx for an offer. It will return transaction object with an order_id field to track the tx status.
.getOrder(<string>)ObjectGet status of the given Order ID string.

* makeOrder input object sample:

{
  depositCoin: 'btc',
  destinationCoin: 'ltc',
  depositCoinAmount: 0.03,
  offerReferenceId: "...", // get it from generateOffer(..)
  userReferenceId: 'test-user',
  destinationAddress: { address: 'LXdmzmqSALB1DbJyA43b6prQCXKn1J6SdV' },
  refundAddress: { address: '16iL2ZM4CfeiH3CrtrNjGVgR6ja2p5AFec' }
}

Example

For more examples look at the unit test/ folder.

Test

npm test

Debug

To enable debug set the env var DEBUG=coinswitch

License

MIT

Keywords

FAQs

Package last updated on 25 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc