Node.js client library
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
.gitignore
LICENSE
README.md
package-lock.json
package.json
tsconfig.json

README.md

Wyre

Node.js client library for the Wyre API.

Install

npm install @wyre/api

Usage

An important note on decimals:

Some currencies, like ETH, have many decimal places. This can cause problems with the many JSON implementations that fail to offer support arbitrary precision numbers. Moreover, IEEE 754 floating point is not in general a good representation for money - it does not necessarily preserve precision.

In the examples below, we have supplied the format parameter as "json_numberstring". This encodes all numbers returned from our API as strings. If you need to perform arithmetic on these numbers, you must use an arbitrary-precision library:

  • bignumber.js: A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic

Alternatively, instead supply the (default) "format":"json" and the API will encode numbers directly in JSON.

const WyreClient = require('@wyre/api').WyreClient
// import {WyreClient} from '@wyre/api'

let wyre = new WyreClient({
    format: "json_numberstring",
    apiKey: "P334FCDXQ4UVAWVPUZ4V",
    secretKey: "4AZEWMYB7CFJWWZMCEWX"
    // baseUrl: "https://api.testwyre.com"
})

wyre.get("/account")
    .then(data => {
        // .. success
    },
    err => {
        // .. error
    })

wyre.get("/transfers", {
    limit: 1,
    offset: 1
})
    .then(successCallback, errorCallback)

wyre.post("/transfers", {
    sourceAmount: "10",
    sourceCurrency: "USD",
    dest: "email:test@sendwyre.com"
})
    .then(successCallback, errorCallback)

Ability to override options used by the Request client on both constructor and per request:

let wyre = new WyreClient({
    format: "json_numberstring",
    apiKey: "P334FCDXQ4UVAWVPUZ4V",
    secretKey: "4AZEWMYB7CFJWWZMCEWX",
    options: {
        timeout: 1500
    }
})
wyre.get("/rates", {}, {
    timeout: 1500
})
    .then(successCallback, errorCallback)

Errors

Example error response:

{
    language: "en",
    exceptionId: "8MAM48",
    compositeType: "",
    subType: "",
    message: "Field dest is required.",
    type: "FieldRequiredException",
    transient: false
}