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

swtc-tum3

v0.1.3

Published

Jingtum JavaScript API, middleware to talk to a Jingtum node over RPC

Downloads

1

Readme

MOAC JavaScript API version 0.1.15.

This is the MOAC compatible JavaScript API which implements the Generic JSON RPC spec as described in the Tum3.md. It's available on npm as a node module, for bower and component as an embeddable js and as a meteor.js package.

  • v0.1.15 Added local MOAC sign and verify signature methods.
  • v0.1.14 Fixed document errors.
  • v0.1.13 Added scs_getBlockList method.
  • v0.1.12 Fixed Readme and missing scs_getMicroChainInfo method.
  • v0.1.11 Added scs method getMicroChainInfo to work with subchain explorer.
  • v0.1.10 Added vnode and scs methods to work with MicroChains.
  • v0.1.9 Added new method to get ip for local node.
  • v0.1.8 Moved git repository to https://github.com/MOACChain/tum3 and fixed some bugs.
  • v0.1.7 Fixed uneven signature R & S.
  • v0.1.6 A complete package with all tests.
  • v0.1.4 First compatible version with MOAC chain.

Some of the methods require running a local MOAC node to use this library. To use vnode methods, need to enable the vnode APIs in MOAC node by: --rpc --rpcport "8545" --rpcapi "tum3,mc,net,vnode"

To use scs methods, need to enable the SCS RPC ports by: --rpc

More information is in Tum3.md or MOAC wiki.

Installation

Node.js

npm install tum3

As Browser module

Bower

bower install tum3

Meteor.js

meteor add moaclib:tum3
  • Include tum3.min.js in your html file. (not required for the meteor package)

Usage

Use the tum3 object directly from global namespace:

var Tum3 = require('tum3');
var tum3 = new Tum3();
console.log(tum3); // {mc: .., net: ...} // it's here!

Set a provider (HttpProvider) with VNODE:

if (typeof tum3 !== 'undefined') {
  tum3 = new Tum3(tum3.currentProvider);
} else {
  // set the provider you want from Tum3.providers
  tum3 = new Tum3(new Tum3.providers.HttpProvider("http://localhost:8545"));
}

Set a provider (HttpProvider using HTTP Basic Authentication)

tum3.setProvider(new tum3.providers.HttpProvider('http://host.url', 0, BasicAuthUsername, BasicAuthPassword));

There you go, now you can use it:

var coinbase = tum3.mc.coinbase;
var balance = tum3.mc.getBalance(coinbase);

To work with SCS servers, need to enable the rpc port on SCS monitors and set the scsProvider for tum3.

if (typeof tum3 !== 'undefined') {
  tum3 = new Tum3(tum3.currentProvider);
} else {
  // set the provider you want from Tum3.providers
  tum3 = new Tum3(new Tum3.providers.HttpProvider("http://localhost:8545"));
  tum3.setScsProvider(new tum3.providers.HttpProvider('http://localhost:8548'));
}

After set the SCS monitor, now you can use it:

mclist=tum3.scs.getMicroChainList();
console.log("SCS MicroChain List:", mclist);

console.log("MicroChain state:", tum3.scs.getDappState(mclist[0]));
console.log("MicroChain blockNumber:", tum3.scs.getBlockNumber(mclist[0]));

More examples are under the example directory

Contribute!

Requirements

  • Node.js
  • npm
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install nodejs-legacy

Building (gulp)

Require install gulp (https://gulpjs.com/) in the system:

npm run-script build

Testing (mocha)

Test all cases. May need to install package mocha first.

mocha

Test a singe function.

mocha test/tum3.mc.coinbase.js 

Some examples

send_mc

Example codes to send moac through signed transaction.

var rawTx = {
      from: src.addr,
      nonce: tum3.intToHex(txcount),
      gasPrice: tum3.intToHex(2000000000),
      gasLimit: tum3.intToHex(2000),
      to: '0xf1f5b7a35dff6400af7ab3ea54e4e637059ef909',
      value: tum3.intToHex(tum3.toSha(value, 'mc')), 
      data: '0x00',
      chainId: chainid
    }
	
var cmd1 = tum3.signTransaction(rawTx, src["key"]);
    
tum3.mc.sendRawTransaction(cmd1, function(err, hash) {
    if (!err){
        console.log("Succeed!: ", hash);
        return hash;
    }else{
        console.log("Tum3 error:", err.message);
        return err.message;
    }

});

contract_deploy

Deploy a contract through tum3 RPC calls. This example requires install solc solc

build a web server to access the MOAC network using this API library.

sign and verify the signatures

Example codes to sign a message using MOAC network and verify the signature.

// Connect with the MOAC network tum3.setProvider(new tum3.providers.HttpProvider('http://gateway.moac.io/mainnet'));

if (!tum3.isConnected()){ console.log("Tum3 RPC is not connected!"); return; }

// Hash the message let sha3Msg = tum3.sha3("HELLO MOAC!");

// Unlock the account 'tacct.addr' before signing let signedData = tum3.mc.sign(tacct.addr, sha3Msg);

// or you can call the local function to get the same result, but require a private key let signedData = tum3.signMcMessage(sha3Msg,tacct.key);

// Verify the signature with the message and the address console.log("Verify:", tum3.verifyMcSignature(sha3Msg, signedData, tacct.addr));

Accounts use the following library for generating private key.

browserify-cryptojs v0.3.1