Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

g-script/just-mining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

just-mining

Node.js wrapper around Just Mining’s API.

Actions Status npm JavaScript Style Guide license

📖 Table of contents

💾 Installation

yarn add just-mining

Node.js version 6 or higher is required.

Note: while Node.js from version 6 is supported, keep in mind that this library is only tested against Node.js 10+.

Back to top

🔰 Usage

const JM = require("just-mining");

const client = new JM({ apiKey: "YOUR_API_KEY" });

await JM.walletAddresses.list();
await JM.hardwares.get("bobs", 12345);
await JM.get("all");
await JM.get(["masternodes", "operations"]);
await JM.get({
  walletAddresses: "all",
  clouds: [12345, 67890],
  hardwares: [
    "bobs",
    {
      type: "asics",
      id: 12345,
    },
  ],
  stakings: "KAVA",
});

Back to top

🏗️ Constructor

When instanciating the constructor, you have to provide parameters as an object with following properties :

  • apiKey (required): API key provided by Just Mining.
  • version (optional): target a specific version of Just Mining’s API.
    • As of today, the only available version is v1.

I do not know how Just Mining is planning to handle next versions. Will they disable older versions, keep all versions in parallel, keep older versions for some time before disabling them? I do not know. I will try to keep this library up-to-date with available versions.

Back to top

📜 Methods

Just Mining’s API is organized around resources. Available resources are:

  • Cloud contracts
  • Hardwares
  • Masternodes
  • Operations
  • Staking contracts
  • Wallet addresses
  • Wallets

Each resource is available as a property of the client object:

client.masternodes
client.hardwares
...and so on

Each and every resource property has two exposed methods which are the following: get and list.

Back to top

client.clouds.get(id)

Get an owned cloud contract.

Arguments

  • id (Number): cloud contract identifier

Returns

  • (Object): Returns an object describing the cloud contract

Throws

  • if id is not provided
  • if id is not a number
  • if cloud contract was not found

Example

await client.clouds.get(571);
// => {
//   id: 571,
//   status: 'inactive',
//   startDate: false,
//   expirationDate: 1535932800,
//   hashrate: 1000000,
//   currencyCode: 'ETC',
//   mined: {
//     ETH: 0.05191667,
//     ZEC: 0.00160224,
//     ETC: 0.09365148
//   }
// }

Back to top

client.clouds.list()

Get all owned cloud contracts.

Returns

  • (Array): Returns an array of objects describing cloud contracts

Throws

  • if cloud contracts were not found

Example

await client.clouds.list();
// => [{
//   id: 571,
//   status: 'inactive',
//   startDate: false,
//   expirationDate: 1535932800,
//   hashrate: 1000000,
//   currencyCode: 'ETC',
//   mined: {
//     ETH: 0.05191667,
//     ZEC: 0.00160224,
//     ETC: 0.09365148
//   }
// }, {
//   id: 6904,
//   status: 'active',
//   startDate: false,
//   expirationDate: 1653682867,
//   hashrate: 100000000,
//   currencyCode: 'GRIN',
//   mined: {
//     GRIN: 0.19518281
//   }
// }]

Back to top

client.hardwares.get(type, id)

Get an owned machine.

Arguments

  • type (String): machine type (asics or bobs)
  • id (Number): machine identifier

Returns

  • (Object): Returns an object describing the machine

Throws

  • if type is not one of asics or bobs
  • if type is not a string
  • if id is not provided
  • if id is not a number
  • if hardware was not found

Example

await client.hardwares.get("bobs", 580099);
// => {
//   serial: 580099,
//   status: 'inactive',
//   uptime: '285',
//   lastActivity: 1568986845,
//   hashrate: 175260000,
//   currencyCode: 'ETH',
//   mined: {
//     ETH: 0.00003053
//   }
// }

Back to top

client.hardwares.list(type)

Get all machines. If type is provided, get all machines of this type.

Returns

If type is provided:

  • (Array): Returns an array of objects describing machines

If type is omitted:

  • (Object): Returns an object with properties matching machine types and containing an array of objects describing machines

Throws

  • if machines were not found

Example

await client.hardwares.list();
// => {
//   asics: [{
//     id: 330,
//     type: 'S17+',
//     status: 'active',
//     hashrate: 36270000000000,
//     currencyCode: 'BTC',
//     uptime: 71640,
//     mined: {
//       BTC: 0.02070824
//     }
//   }],
//   bobs: [{
//     serial: 580099,
//     status: 'inactive',
//     uptime: '285',
//     lastActivity: 1568986845,
//     hashrate: 175260000,
//     currencyCode: 'ETH',
//     mined: {
//       ETH: 5.00003053
//     }
//   }]
// }

await client.hardwares.list("bobs");
// => [{
//   serial: 580099,
//   status: 'inactive',
//   uptime: '285',
//   lastActivity: 1568986845,
//   hashrate: 175260000,
//   currencyCode: 'ETH',
//   mined: {
//     ETH: 5.00003053
//   }
// }]

Back to top

client.masternodes.get(id)

Get an owned masternode.

Arguments

  • id (Number): masternode identifier

Returns

  • (Object): Returns an object describing the masternode

Throws

  • if id is not provided
  • if id is not a number
  • if masternode was not found

Example

await client.masternodes.get(9208);
// => {
//   id: 9208,
//   status: 'active',
//   collateral: 250,
//   currencyCode: 'BITG',
//   reward: 0.00149775,
//   startDate: 1590739635,
//   endDate: null
// }

Back to top

client.masternodes.list()

Get all owned masternodes.

Returns

  • (Array): Returns an array of objects describing masternodes

Throws

  • if masternodes were not found

Example

await client.masternodes.list();
// => [{
//   id: 9208,
//   status: 'active',
//   collateral: 250,
//   currencyCode: 'BITG',
//   reward: 0.00149775,
//   startDate: 1590739635,
//   endDate: null
// }, {
//   id: 9224,
//   status: 'active',
//   collateral: 4.2,
//   currencyCode: 'ZEN-42',
//   reward: 0.00001253,
//   startDate: 1590739640,
//   endDate: null
// }]

Back to top

client.operations.get(id)

Get an operation (withdrawal, exchange, debit or credit).

Arguments

  • id (Number): operation identifier

Returns

  • (Object): Returns an object describing the operation

Throws

  • if id is not provided
  • if id is not a number
  • if operation was not found

Example

await client.operations.get(5412);
// => {
//   id: 5412,
//   type: 'withdraw',
//   status: 'paid',
//   date: 1544977587,
//   sourceCurrencyCode: 'ETC',
//   sourceAmount: 1,
//   destinationCurrencyCode: 'ETC',
//   destinationAmount: 0,
//   destinationAddress: '0x........................',
//   memo: null
// }

Back to top

client.operations.list()

Get all account operations.

Returns

  • (Array): Returns an array of objects describing operations

Throws

  • if operations were not found

Example

await client.operations.list();
// => [{
//   id: 3010,
//   type: 'withdraw',
//   status: 'paid',
//   date: 1538914035,
//   sourceCurrencyCode: 'ETH',
//   sourceAmount: 3.7,
//   destinationCurrencyCode: 'ETH',
//   destinationAmount: 0,
//   destinationAddress: '0x..................',
//   memo: null
// }, {
//   id: 4027,
//   type: 'withdraw',
//   status: 'paid',
//   date: 1537115656,
//   sourceCurrencyCode: 'ETH',
//   sourceAmount: 0.517,
//   destinationCurrencyCode: 'ETH',
//   destinationAmount: 0,
//   destinationAddress: '0x....................',
//   memo: null
// }, {
//   id: 5181,
//   type: 'exchange',
//   status: 'paid',
//   date: 1536862720,
//   sourceCurrencyCode: 'ZEC',
//   sourceAmount: 0.00370617,
//   destinationCurrencyCode: 'ETH',
//   destinationAmount: 0.00233272
// }, {
//   id: 4522,
//   type: 'credit',
//   status: 'paid',
//   date: 1532299229,
//   currencyCode: 'BCARD',
//   amount: 5,
//   details: 'Masternode sale'
// }]

Back to top

client.stakings.get(currencyCode)

Get an owned staking contract.

Arguments

  • currencyCode (String): staking contract currency code

Returns

  • (Object): Returns an object describing the staking contract

Throws

  • if currencyCode is not provided
  • if currencyCode is not a string
  • if staking contract was not found

Example

await client.stakings.get("KAVA");
// => {
//   currencyCode: 'KAVA',
//   amount: 75,
//   reward: 0.01027898,
//   lockedReward: 0,
//   startDate: 1590582716,
//   variations: [
//     {
//       amount: 75,
//       date: 1590582716,
//       effectiveDate: 1590669116,
//       applied: 1
//     }
//   ],
//   credits: [
//     {
//       amount: 0.00432936,
//       date: 1590710400,
//       releaseDate: false,
//       released: 1
//     },
//     {
//       amount: 0.00594962,
//       date: 1590624000,
//       releaseDate: false,
//       released: 1
//     }
//   ]
// }

Back to top

client.stakings.list()

Get all owned staking contracts.

Returns

  • (Array): Returns an array of objects describing staking contracts

Throws

  • if staking contracts were not found

Example

await client.stakings.list();
// => [{
//   currencyCode: 'KAVA',
//   amount: 75,
//   reward: 0.01027898,
//   lockedReward: 0,
//   startDate: 1590582716,
//   variations: [
//     {
//       amount: 75,
//       date: 1590582716,
//       effectiveDate: 1590669116,
//       applied: 1
//     }
//   ],
//   credits: [
//     {
//       amount: 0.00432936,
//       date: 1590710400,
//       releaseDate: false,
//       released: 1
//     },
//     {
//       amount: 0.00594962,
//       date: 1590624000,
//       releaseDate: false,
//       released: 1
//     }
//   ]
// }, {
//   currencyCode: 'SNX',
//   amount: 500,
//   reward: 0,
//   lockedReward: 0,
//   startDate: 1590594695,
//   variations: [
//     {
//       amount: 500,
//       date: 1590594695,
//       effectiveDate: 1590681095,
//       applied: 1
//     }
//   ],
//   credits: []
// }]

Back to top

client.walletAddresses.get(currencyCode, id)

Get an owned address.

Arguments

  • currencyCode (String): address currency code
  • id (Number): address identifier

Returns

  • (Object): Returns an object describing the address

Throws

  • if currencyCode is not provided
  • if currencyCode is not a string
  • if id is not provided
  • if id is not a number
  • if address was not found

Example

await client.walletAddresses.get("BNB", 11402);
// => {
//   id: 11402,
//   currencyCode: 'BNB',
//   name: null,
//   address: 'bnb.....................',
//   isBEP2: true,
//   memo: 'memo',
// }

Back to top

client.walletAddresses.list(currencyCode)

Get all addresses. If currencyCode is provided, returns all addresses for this currency code.

Returns

  • (Array): Returns an array of objects describing addresses

Throws

  • if addresses were not found

Example

await client.walletAddresses.list();
// => [{
//   id: 11401,
//   currencyCode: 'ETH',
//   name: null,
//   address: '0x............................',
//   isBEP2: false,
//   memo: null,
// }, {
//   id: 11402,
//   currencyCode: 'BNB',
//   name: null,
//   address: 'bnb.....................',
//   isBEP2: true,
//   memo: 'memo',
// }]

await client.walletAddresses.list("ETH");
// => [{
//   id: 11401,
//   currencyCode: 'ETH',
//   name: null,
//   address: '0x............................',
//   isBEP2: false,
//   memo: null,
// }]

Back to top

client.wallets.get(currencyCode)

Get an owned wallet.

Arguments

  • currencyCode (String): wallet currency code

Returns

  • (Object): Returns an object describing the wallet

Throws

  • if currencyCode is not provided
  • if currencyCode is not a string
  • if wallet was not found

Example

await client.wallets.get("ETH");
// => {
//   currencyCode: 'ETH',
//   balance: 0.03190596
// }

Back to top

client.wallets.list()

Get all owned wallets.

Returns

  • (Array): Returns an array of objects describing wallets

Throws

  • if wallets were not found

Example

await client.wallets.list();
// => [{
//   currencyCode: 'ZEC',
//   balance: 0.00160223
// }, {
//   currencyCode: 'ETH',
//   balance: 0.03190596
// }, {
//   currencyCode: 'ETC',
//   balance: 0.09259209
// }]

Back to top

🪲 Debugging

This library uses debug package internally. You can enable debug logs by setting the DEBUG environment variable to just-mining:*.

You can target a specific resource debug logs by being more specific: DEBUG=just-mining:v1:walletAddresses.

Back to top

🎲 Running tests

This package is tested against multiple different scenarios with Mocha and chai (through expect BDD style). It also rely on nock to mock API responses.

In order to run tests locally, you have to:

  • clone this repository
  • install development dependencies with yarn install
  • run tests with yarn test

Tests are run in bail mode. This means that whenever a test fails, all following tests are aborted.

Back to top

🔢 Versioning

This project uses SemVer for versioning. For the versions available, see the tags on this repository.

Back to top