@elevenyellow.com/switchain-api-client

client module to access switchains's api

Usage no npm install needed!

<script type="module">
  import elevenyellowComSwitchainApiClient from 'https://cdn.skypack.dev/@elevenyellow.com/switchain-api-client';
</script>

README

Install

npm i @elevenyellow.com/switchain-api-client

Docs

https://apidoc.switchain.com/

Initialize

const { init } = require('switchain-api-client')
const SwitchainApi = init({
  apiKey: 'xxxxxxxx-yyyy-zzzz-0000-999999999999',
  apiUrl: 'http://localhost:3020/rest/v1/' // optional
})

API

getOffers

Returns

{
    info: [ { signature, expiryTs, pair, fromChains, toChains, quote, maxLimit, minLimit, minerFees }, ... ]
}

Example

const { info } = SwitchainApi.getOffers()

getOffer

Params

  • pair: string (required)
  • amountFrom: string
  • orderIdSeed: string

Returns

{
  offer: {
    signature, expiryTs, pair, quote, maxLimit, minLimit
  }
}

Example

const { offer } = SwitchainApi.getOffer({
  pair: 'ETH-DAI'
})

postOrder

Params

  • pair: string
  • toAddress: string
  • refundAddress: string
  • fromAmount: string
  • signature: string

Returns

{
  order: {
    orderId, fromAmount, rate, exchangeAddress, toAddress, refundAddress
  }
}

Example

const { offer } = SwitchainApi.postOrder({
  toAddress,
  refundAddress,
  pair,
  fromAmount,
  signature
})

getOrder

Params

  • orderId: string

Returns

{
  status: {
    status, fromAmount, rate, exchangeAddress, toAddress, refundAddress, toTx
  }
}

Example

const { status } = SwitchainApi.getOrder({ orderId })