npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@galacticexchange/gex-client-js

v0.2.24

Published

Galactic Exchange client tools

Downloads

70

Readme

gex-client-js

Galactic Exchange client tools.
You can use this library to develop browser and Node.js applications that use Galactic Exchange.

Documentation (v. 0.2+)

This README contains outdated documentation (for v.0.1.4).
You can find documentation for the current version here: https://galacticexchange.github.io/gex-client-js/

Old documentation (v. 0.1)

Installation

NPM

npm install @galacticexchange/gex-client-js

Yarn

yarn add @galacticexchange/gex-client-js

Initialization

The package includes both non-minified version and a minified version. For web browsers you will typycally use non-minified version for development and minified version for production mode.
For Node.js projects you will need to use non-minified version.

Require library (minified)

const gex = require('@galacticexchange/gex-client-js');

Require library (non-minified)

const gex = require('@galacticexchange/gex-client-js/src/index');

Init library

Find out the IP addess and port of the Ethereum blockchain node that you want to connect to.
Note that the standard port is 8546. Use the address and the port to init the library as illustrated in the example below.

Note: your blockchain node needs to have WebSockets enabled.

let wsAddr = 'ws://0.0.0.0:8546'; // address of the web3 web socket provider
gex.init(wsAddr);

Usage

Main functionality

Create node

// lib init, then:
let ip = '255.255.255.255';
let port = 6000;
gex.createNode(ip, port);

Create mChain

mChain is used to execute transactions and smart contracts. To create an mChain you need to specify the following parametrs:

  • storage bytes
  • lifetime of the chain (in seconds)
  • number of nodes in chain
  • deposit
let storageBytes = 1111;
let lifetime = 355;
let maxNodes = 123;
let deposit = 4444;
gex.managerContract().createBasicMchain(storageBytes, lifetime, maxNodes, deposit);

Create aggregation mChain

let storageBytes = 245678;
let lifetime = 3456789;
let maxNodes = 444;
let deposit = 8909;
gex.managerContract().createAggregationMchain(storageBytes, lifetime, maxNodes, deposit);

Get basic mChain

Get info for basic channel by id

async function test() {
  let channel = await gex.managerContract().getBasicChannel(2);
  console.log(channel);
}

Get basic mChain list (with info)

Get an array of basic mChains for current account (with info)

async function test() {
  let channelsInfo = await gex.managerContract().getBasicChannelListInfo();
  console.log(channelsInfo);
}

Get basic mChain list (id only)

async function test() {
  let channelsIds = await gex.managerContract().getBasicChannelList();
  console.log(channelsIds);
}

Same for aggregation mChains:

async function test() {
  let aggrChannelsIds = await gex.managerContract().getAggregationChannelList();
  let aggrChannel = await gex.managerContract().getAggregationChannel(2);
  let aggrChannels = await gex.managerContract().getAggregationChannelListInfo();
}

Withdraw from mChains

// lib init, then:
gex.managerContract().withdrawFromChannels();

Listeners

Full example of nodeCreated listener usage

const gex = require('../src/index');

class Test {

  constructor(){
    this.val = 0;
    let wsAddr = 'ws://51.0.1.99:8546';
    gex.init(wsAddr);
    this.initListener();
  }

  initListener(){
    let self = this;
    let listener = new gex.listener(gex.managerContract().events.NodeCreated(), function (event) {
      console.log(event.returnValues);
      self.val = event.returnValues.nodeID;
      self.checkValue();
    });
  }

  createNode(){
    gex.createNode('255.255.255.255', 6000);
  }

  checkValue(){
    console.log('Check value: ');
    console.log(this.val)
  }

}

let ts = new Test();
ts.createNode();

Available events

Updated for v. 0.0.14
Usage example:

// gex v. 0.0.14
let listener = new gex.listener(gex.manager().events.MchainCreated(), function (event) {
   console.log('EVENT');
   console.log(event.returnValues);
});

Manager contact

  • NodeCreated
  • MchainCreated
  • AggregationMchainCreated
  • MchainAdded

Token contact

// todo

Short API

// todo

Other

Check balance

async function checkBalances() {
  let accounts = await gex.gexWeb3.getAccounts();
  let firstAccountBalance = await gex.tokenContract().balanceOf(accounts[0]);
  console.log('first account balance: ' + firstAccountBalance);

  let tokenAddr = gex.managerContract().contractAddress;
  let nodeManagerBalance = await gex.tokenContract().balanceOf(tokenAddr);
  console.log('node manager balance: ' + nodeManagerBalance);
}

Init with custom web3 provider

const gcjs = require('../src/GexClientJs');   

// custom web3 provider
let web3Provider = new Web3.providers.WebsocketProvider();
gcjs.initWithProvider(web3Provider)

Dev init with custom contract

const gcjs = require('../src/GexClientJs');   

let wsAddr = 'ws://0.0.0.0:8546';
let abi = { };
let contractAddress = '0x345678...';
gcjs.devInit(wsAddr, abi, contractAddress)

Contribution

Requirements

  • Node.js
  • npm

Build

npm run build

Testing (mocha)

npm run test