Coder Social home page Coder Social logo

torus-client's Introduction

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

torus-client's People

Contributors

dependabot[bot] avatar fresheneesz avatar intech avatar juscamarena avatar lautarodragan avatar pedrobranco avatar ruimarinho avatar sskender avatar toriaezunama avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

22388o

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.