Skip to content

torus-economy/torus-client

Repository files navigation

torus-client

Torus REST and RPC client

Installation

Install the package via yarn:

yarn add https://github.com/torus-economy/torus-client

or via npm:

Install the package via npm:

npm install --save https://github.com/torus-economy/torus-client

Usage

Client(...args)

Arguments

  1. [agentOptions] (Object): Optional agent options to configure SSL/TLS.
  2. [headers=false] (boolean): Whether to return the response headers.
  3. [host=localhost] (string): The host to connect to.
  4. [logger=debugnyan('torus-client')] (Function): Custom logger (by default, debugnyan).
  5. [network=mainnet] (string): The network.
  6. [password] (string): The RPC server user password.
  7. [port=24111] (string): The RPC server port.
  8. [ssl] (boolean|Object): Whether to use SSL/TLS with strict checking (boolean) or an expanded config (Object).
  9. [ssl.enabled] (boolean): Whether to use SSL/TLS.
  10. [ssl.strict] (boolean): Whether to do strict SSL/TLS checking (certificate must match host).
  11. [timeout=30000] (number): How long until the request times out (ms).
  12. [username] (number): The RPC server user name.
  13. [version] (string): Which version to check methods for.
  14. [wallet] (string): Which wallet to manage.

Examples

Basic client settings

const Client = require('torus-client')

const client = new Client({
  host: '127.0.0.1',
  password: 'somepassword',
  port: 24111,
  username: 'someusername'
 });

Connecting to an SSL/TLS server with strict checking enabled

By default, when ssl is enabled, strict checking is implicitly enabled.

const fs = require('fs');
const client = new Client({
  agentOptions: {
    ca: fs.readFileSync('/etc/ssl/torusd/cert.pem')
  },
  ssl: true
});

Connecting to an SSL/TLS server without strict checking enabled

const client = new Client({
  ssl: {
    enabled: true,
    strict: false
  }
});

Using promises to process the response

client.getBalance().then((bal) => console.log(bal));

Floating point number precision in JavaScript

Due to JavaScript's limited floating point precision, all big numbers (numbers with more than 15 significant digits) are returned as strings to prevent precision loss. This includes both the RPC and REST APIs.

License

MIT