coinswitch-v2

Coinswitch.co v2 API javascript client

Usage no npm install needed!

<script type="module">
  import coinswitchV2 from 'https://cdn.skypack.dev/coinswitch-v2';
</script>

README

coinswitch-v2 GitHub license GitHub top language David

Browser and Node.js Coinswitch.co API v2 client

Easily exchange crypto coins with few lines of code.


Install

npm install --save coinswitch-v2

Usage

/** import { CoinSwitchDynamic } from 'coinswitch-v2' */ // Typescript import
const { CoinSwitchDynamic } = require('coinswitch-v2')

;(async () => {
  const cs = new CoinSwitchDynamic({
    apiKey: '<YOUR API KEY>',
    userIP: '<YOUR IP>' // Default is 1.1.1.1
  })

  // Get all coins you can trade
  const coins = await cs.getCoins()
  console.log(coins)

  // Generate an exchange offer for for a coin pair
  const rate = await cs.getExchangeRate({
    depositCoin: 'btc',
    destinationCoin: 'eth',
    depositCoinAmount: 0.03
  })
  console.log(rate)

  // Make a trade order
  const order = await cs.createOrder({
    depositCoin: 'btc',
    destinationCoin: 'eth',
    depositCoinAmount: 0.03,
    destinationAddress: {
      address: '0xcc1bf6b0625bc23895a47f4991fdb7862e34a563'
    },
    refundAddress: {
      address: '0xcc1bf6b0625bc23895a47f4991fdb7862e34a563'
    }
  })

  console.log(order)
})()

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


API KEY

Get your api-key from the coinswitch API page.


Example

For more examples look into the __tests__ folder on GitHub.

Test

npm test

License

MIT