GithubHelp home page GithubHelp logo

nikhiljha / nem-api Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 8.0 1.21 MB

API Wrapper for the NIS Layer of the NEM Blockchain Platform

JavaScript 100.00%
blockchain api-wrapper nem nem-blockchain-platform

nem-api's Introduction

Deprecated: Use nem-sdk instead.

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

nem-api's People

Contributors

alexsey avatar evias avatar jorisadri avatar nikhiljha avatar saddam213 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nem-api's Issues

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.