Skip to content
Javascript SDK for the Syscoin cryptocurrency.
TypeScript JavaScript
Branch: master
Clone or download
Dan Wasyluk Dan Wasyluk
Dan Wasyluk and Dan Wasyluk 4.0.4
Latest commit b87ac51 Jul 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_tests_ passing unit tests Jun 9, 2019
dist type updates Jul 3, 2019
src type updates Jul 3, 2019
.gitignore add dist May 15, 2019
README.md Update README.md Jun 19, 2019
jest.config.js test, build packaging May 15, 2019
package-lock.json
package.json
tsconfig.json size optimization, remove sourcemaps Jun 9, 2019
webpack.config.js

README.md

syscoin-js

A javascript library for interacting directly with the Syscoin RPC Server. Provides 1:1 mappings for all RPC endpoints. For full endpoint list see RPCFunctions.ts. Built for NodeJS or for browser.

Installation

npm install @syscoin/syscoin-js

Usage

Works as a Typescript library or a ES6 Javascript library. Calls can be made individually or batched. Typescript helper interfaces for request and response object can be found in src/model/request and src/model/response.

Typescript

import { SyscoinRpcClient, rpcServices } from "@syscoin/syscoin-js";

const config = {
  host: "localhost",
  rpcPort: 8368,
  username: "u",
  password: "p",
  logLevel: 'error'
};
const client = new SyscoinRpcClient(config);
const info = await rpcServices(client.callRpc).getBestBlockHash().call();

NodeJS

const SyscoinRpcClient = require("@syscoin/syscoin-js").SyscoinRpcClient;
const rpcServices = require("@syscoin/syscoin-js").rpcServices;

const config = {
  host: "localhost",
  rpcPort: 8368, // This is the port used in the docker-based integration tests, change at your peril
  username: "u",
  password: "p",
  logLevel: 'error'
};
const client = new SyscoinRpcClient(config);
const info = rpcServices(client.callRpc).getBestBlockHash().call();

Batch Calls

Batch requests can be constructed using the batch function. Results will be an array based on the requests.

const result = await client.batch([
  rpcServices(client.callRpc).getBestBlockHash(),
  rpcServices(client.callRpc).getWallteInfo()]);

// result[0] = getBestBlockHash result
// result[1] = getWalletInfo result

Wrapped and Unwrapped Responses

The Syscoin RPC server returns results wrapped in an object - {rersult: null, id: null, error: null }. By default syscoin-js will unwrap RPC responses to provide consumers with data.result or data.error directly. Consumers can optionally disable this to process the full wrapped object.

Example single call with unwrapping disabled

const result = await rpcServices(client.callRpc).getBestBlockHash().call(false);

Example batch call with unwrapping disabled

const result = await client.batch([
  rpcServices(client.callRpc).getBestBlockHash(),
  rpcServices(client.callRpc).getWallteInfo()], false);

Contributing

Please submit all updates and improvements via pull request.

You can’t perform that action at this time.