JSPM

@nowpaymentsio/nowpayments-api-js

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 274
  • Score
    100M100P100Q106772F
  • License MIT

A library for interacting with the NOWPayments API

Package Exports

  • @nowpaymentsio/nowpayments-api-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nowpaymentsio/nowpayments-api-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NOWPayments API

Build Status

A library for interacting with the NOWPayments API.

Installation

Using npm:

$ npm install @nowpaymentsio/nowpayments-api-js

Using unpkg CDN:

<script src="https://unpkg.com/@nowpaymentsio/nowpayments-api-js/dist/nowpayments-api-js.min.js"></script>

Examples

Node JS

const NowPaymentsApi = require('@nowpaymentsio/nowpayments-api-js');

const api = new NowPaymentsApi({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key
async function logCurrencies() {
  const { currencies } = await api.getCurrencies()
  console.log(currencies)
}
logCurrencies()

React

import React from 'react'
import NowPaymentsApi from '@nowpaymentsio/nowpayments-api-js'

const npApi = new NowPaymentsApi({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key

const App = () => {
  const [currenciesArr, setCurrenciesArr] = React.useState([])
  React.useEffect(() => {
    async function fetchCurrencies() {
      const { currencies } = await npApi.getCurrencies()
      setCurrenciesArr(currencies)
    }
    fetchCurrencies()
  }, [])

  return (
    <div>
      <h2>Available currencies</h2>
      <br />
      {currenciesArr.map((currency) => (
        <p>{currency}</p>
      ))}
    </div>
  )
}

export default App
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>NOWPayments API - HTML Example</title>
  <script src="../../dist/nowpayments-api-js.min.js"></script>
</head>

<body>
  <h4>Available currencies</h4>
  <script>
    const body = document.body;
    const api = new NOWPaymentsApi({ apiKey: 'A7M40XV-CG1448Z-KVVED3G-NW3V0TK' }) // your api key

    async function fetchCurrencies() {
      const { currencies } = await api.getCurrencies()
        const selectList = document.createElement("select")
        selectList.id = "mySelect"
        body.appendChild(selectList)

      for (var i = 0; i < currencies.length; i++) {
        const option = document.createElement("option")
        option.value = currencies[i]
        option.text = currencies[i]
        selectList.appendChild(option)
      }
    }
    fetchCurrencies()
  </script>
</body>
</html>