coinhive-lib
v1.0.5
Published
node wrapper for Coinhive HTTP API
Downloads
6
Readme
coinhive-lib.js
node wrapper for Coinhive HTTP API
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
- User: balance
- User: withdraw
- User: top users
- User: list users
- User: reset user
- User: reset all users
- Link: create
- Stats: payout
- Stats: site
- Stats: history
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))
})