Giter VIP home page Giter VIP logo

nkn-client-js's Introduction

CircleCI Status

nkn-client-js

JavaScript implementation of NKN client.

Send and receive data between any NKN clients without setting up a server.

Note: This is a client version of the NKN protocol, which can send and receive data but not relay data (mining). For node implementation which can mine NKN token by relaying data, please refer to nkn.

Note: This repository is in the early development stage and may not have all functions working properly. It should be used only for testing now.

Usage

For npm:

npm install nkn-client

And then in your code:

const nkn = require('nkn-client');

For browser, use dist/nkn.js or dist/nkn.min.js.

Create a client with a generated key pair:

const client = nkn();

Or with an identifier (used to distinguish different clients sharing the same key pair):

const client = nkn({
  identifier: 'any string',
});

Get client key pair:

console.log(client.key.privateKey, client.key.publicKey);

Create a client using an existing private key:

const client = nkn({
  identifier: 'any string',
  privateKey: 'cd5fa29ed5b0e951f3d1bce5997458706186320f1dd89156a73d54ed752a7f37',
});

Create a client using customized bootstrap RPC server (for getting node address):

const client = nkn({
  identifier: 'any string',
  seedRpcServerAddr: 'https://xxx',
});

Private key should be kept SECRET! Never put it in version control system like here.

Get client identifier:

console.log(client.identifier);

And client NKN address, which is used to receive data from other clients:

console.log(client.addr);

Listen for connection established:

client.on('connect', () => {
  console.log('Connection opened.');
});

Send data to other clients:

client.send(
  'another client address',
  'some message',
);

Receive data from other clients:

client.on('message', (src, payload) => {
  console.log(src, payload);
});

nkn-client-js's People

Contributors

yilunzhang avatar

Watchers

 avatar  avatar

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.