npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinhive-lib

v1.0.5

Published

node wrapper for Coinhive HTTP API

Downloads

6

Readme

coinhive-lib.js

node wrapper for Coinhive HTTP API

NPM

github repo link

Install:

npm i coinhive-lib

Simple to use

coinhive-lib.js is a wrapper for the Coinhive HTTP API, its really simple and it comes in two flavours, traditional with callback and a promise api

const { CoinhiveLib, CoinhivePromiseLib } = require('coinhive-lib')
const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhivePromise.statsSite()
  .then(body => console.log(body))
  .catch(error => console.error(error));

coinhive.statsSite((error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
}

Like it? buy me a beer!

BTC: 1M8sQivGiMx2f3R6rP3raTq5PDbnTHeC5n

XMR: 4A76foXYghp1WBDjLjA4EDPwsvAisHRQY3tq8cUkBuducW6WkyhcU2EX5qiSxFdLQFLVaeeZcUhJULjwyBYeJFRdKVh2BxM

Methods


Token verify

Coinhive endpoint: /token/verify

Verify that a token from a CoinHive.Token miner has reached a number of hashes. Tokens are only valid for 1 hour. Note that a token can only be verified once. All subsequent requests to verify the same token will result in the invalid_token error.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.verify({ token: 'yourtoken', hashes: 'yourhash' }, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.verify({ token: 'yourtoken', hashes: 'yourhash' })
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: balance

Coinhive endpoint: /user/balance

Get the total number of hashes, the withdrawn hashes and the current balance for a user name. Think of it as the balance of a bank account. Hashes can be paid in through mining, and withdrawn through /user/withdraw.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.userBalance({ name: 'username' }, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.userBalance({ name: 'username' })
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: withdraw

Coinhive endpoint: /user/withdraw

Withdraw a number of hashes for a user name. If successful, the requested amount will be subtracted from the user's balance.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.userWithdraw({ name: 'username', amount: 'amount' }, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.userWithdraw({ name: 'username', amount: 'amount' })
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: top users

Coinhive endpoint: /user/top

Get a list of top users ordered by total number of hashes, balance or hashes withdrawn.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.userTop((error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.userTop()
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: list users

Coinhive endpoint: /user/list

Get a paginated list of all users in alphabetical order. Note that this will only return users with a total number of hashes greater than 0.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.userList({ count: 'count', page: 'npage', order: 'sortType' }, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.userList({ count: 'count', page: 'npage', order: 'sortType' })
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: reset user

Coinhive endpoint: /user/reset

Reset a user's total hashes and withdrawn amount to 0.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.userReset({ name: 'username'}, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.userReset({ name: 'username'} )
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

User: reset all users

Coinhive endpoint: /user/reset-all

Reset the hashes and withdrawn amount for all users for this site to 0.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.resetAll((error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.resetAll()
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

Link: create

Coinhive endpoint: /link/create

Create a new shortlink. You can also do this by hand, directly from your dashboard.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.linkCreate({ url: 'https://www.google.com', hashes: '10' }, (error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.linkCreate({ url: 'https://www.google.com', hashes: '10' } )
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

Stats: payout

Coinhive endpoint: /stats/payout

Get the current payout rate and stats about the network.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.statsPayout((error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.statsPayout()
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

Stats: site

Coinhive endpoint: /stats/site

Get the current hashrate, total hashes, paid & pending xmr, and the hourly history for the past seven days for the site.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.statsSite((error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.statsSite()
  .then(body => console.log(body))
  .catch(error => console.error(error))
})

Stats: history

Coinhive endpoint: /stats/history

Get the hourly history of total hashes and hashes/s for a time period for the site.

Usage

const coinhive = CoinhiveLib('YOUR COINHIVE KEY HERE')

coinhive.statsHistory({ begin: 'unixtimstampbegin', end: 'unixtimestampend'},(error, response, body) => {
  if (error) {
    console.error(error);
  } else {
    console.log(body)
  }
})

Usage with promise

const coinhivePromise = CoinhivePromiseLib('YOUR COINHIVE KEY HERE')
coinhivePromise.statsHistory({ begin: 'unixtimstampbegin', end: 'unixtimestampend'})
  .then(body => console.log(body))
  .catch(error => console.error(error))
})