Skip to content

API Wrapper for the NIS Layer of the NEM Blockchain Platform

Notifications You must be signed in to change notification settings

jorisadri/nem-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nem-api

Advanced API Wrapper for the NIS Layer of the NEM Blockchain Platform

npm version build status

Features

IMPORTANT: Are you a buisness looking to build on NEM? Priority support is offered, please email me at [email protected].

  • Signing
  • NIS Management
  • Fully commented code for anyone to learn from!

Installation

Just like anything else on npm, just do npm install nem-api --save.

Usage Examples

This is incomplete, and more features are being added. It should be fairly simple if you read these examples and the code.

Initialization

var nemapi = require('nem-api');
var san = new nemapi('http://san.nem.ninja:7890');

The API URL can be null if you just want signing. In fact, a lot of things can be null, everything is properly handled.

Signing

var signature = san.sign(hexPrivateKey, thingToSign);
console.log(signature);

Verifying

TODO: Implement verifying, when it's done it'll probably look like this.

if (san.verify(thingThatWasSigned, hexPublicKey)) {
  console.log("Signature checks out!");
} else {
  console.log("Bad signature! Is it an impostor?!?!?");
}

NIS Requests

san.get('/account/get', {'address': 'YOUR_ADDRESS'}, function(response) {
  console.log(response.body);
});

For post requests just use san.post. Note that response.body is a javascript object already, and does not need to be parsed in order to access the insides.

Making a Transaction Object

A transaction object looks like this.

var txobject = {
  'isMultisig': false,
  'recipient': "TXXX-XXXX-XXXX-XXX", // Dashes optional, all parsed later.
  'amount': 1, // Amount of XEM to send.
  'message': 'Hello reciever!', // Message to send.
  'due': 60 // Not sure what this does but the default is probably fine.
}

You can send this transaction in a couple ways.

You can make it, serialize it, then send it yourself.

var transaction = this.makeTX(transactionobject, privatekey);
var transactionobject = this.signTX(transaction, privatekey);
this.post('/transaction/announce', transactionobject, callback);

Or you can just give it to the doTX() function and it'll handle that all for you.

san.doTX(transactionobject, privatekey, callback);

The callback is a regular post() callback, so it is passed an object called response, which contains response.body (parsed JSON).

Using WebSockets

Have an example, it should be self explanatory.

This does not work on web. For web you do the same thing in my code except you

var nem = require('nem-api');
var bob = new nem("http://bob.nem.ninja:7890/")

function getNewBlocks() {
    var thing = bob.subscribeWS("/blocks/new", function(message) {
        console.log(message.body);
    });
    // Later you can thing.unsubscribe(); so keep this object safe.
}

bob.connectWS(function () {
    getNewBlocks();
}, function() {
  console.log("This runs in case of a failure.");
});

Donations

I'd love donations for this project especially if you make money by using it.

Donation Counter: 0 XEM / 0.000 BTC

XEM: NDLL32-E2LU3M-BOUFCO-ERHSLK-A3O62C-KABXYG-4JYE / BTC: 1Csp78BhddGz9Qj6cF4yc3bnC9Kv49G82f

About

API Wrapper for the NIS Layer of the NEM Blockchain Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%