Socket
Book a DemoInstallSign in
Socket

bitcoinfees-insight

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

bitcoinfees-insight

bitcoinfees from insight

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

node-bitcoinfees-insight

NPM
Build Status Coverage Status

bitcoinfees from insight

install

npm i bitcoinfees-insight

Usage

  • code
var bitcoinfees = require('bitcoinfees-insight');
bitcoinfees.FeesApi.recommended().then(function(res){
    console.log(res)
})
  • result
{ "fastestFee": 40, "halfHourFee": 20, "hourFee": 10 }
  • mapping estimatefee
 "fastestFee": Math.round(nbBlocks=2 * 1.05)
 "halfHourFee": Math.round(nbBlocks=2)
 "hourFee": Math.round(nbBlocks=3)

HTTP Error Handling

simple error control

bitcoinfees.FeesApi.recommended().catch(function(e){
    console.log(e.message)
})

technical error control

var errors = require('bitcoinfees-insight/errors')
bitcoinfees.FeesApi.recommended()
    .catch(errors.StatusCodeError, function (reason) {
        // HTTP STATUS ERROR(404 or 500, 502, etc...)
        console.log("HTTP StatusCodeError " + reason.statusCode, "HTTP", reason.statusCode)
    })
    .catch(errors.RequestError, function (reason) {
        // REQUEST ERROR(SYSTEMCALL, TIMEOUT)
        console.log(reason.message, "SYSCALL", reason.error.code)
    })
    .catch(function(e){
        // OTHER ERROR
        console.log(e.message)
    })

VALUE Error Handling

var bitcoinfees = require('bitcoinfees-insight');
var assert = require('assert');
var clamp = function(value, min, max){
    return Math.min(Math.max(min, value), max)
}
bitcoinfees.FeesApi.recommended().then(function(res){
    assert(res.hourFee > 0);
    return clamp(res.hourFee, 20, 200) // The API obstacle leads to loss
})

Change Insight URL

var bitcoinfees = require('bitcoinfees-insight');
bitcoinfees.Constant.API_BASE_URL = "https://www.localbitcoinschain.com/api";
bitcoinfees.FeesApi.recommended()

memo

It is better to store it in the database when using it on the server

Keywords

bitcoin

FAQs

Package last updated on 14 Mar 2017

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