Code Monkey home page Code Monkey logo

karmachain's Introduction

karmachain

Package for work with Karma blockchain

Setup

This library can be obtained through npm:

# npm install karmachain

Usage

karmachain package contain class Karma:

const Karma = require("karmachain")

Kamra contains static methods for work with public API, and dynamic methods for work with wallet API.

Initialization

Example initialization:

Karma.init('wss://node.karma.red')

After initialization, you can connect:

Karma.connect()

Karma.connect() return Promise, resolve it when connection consists.

You may to subscribe to connection event:

Karma.subscribe('connected',functionToCall)

Public API

After connection, you may call public api methods. For example Karma.db return wrapper for database API:

Karma.db.get_objects(["1.3.0"])
Kamra.db.list_assets("krm",100)

Karma.history is wrapper for history API:

Karma.history.get_account_history("<account_id>", "1.11.0", 10, "1.11.0")

Private API

If you want access to private API, you need create object from Karma class:

let account = new Karma("accountName","privateActiveKey")

or

let account = Karma.login("accountName","password")

account have transfer method:

await account.transfer(toName, assetSymbol, amount, memo)

Some examples:

const Karma = require('karmachain')
KEY = 'privateActiveKey'

Karma.init('wss://node.karma.red')
Karma.subscribe('connected', startAfterConnected)

async function startAfterConnected() {
  let bot = new Karma('test-acc',KEY)

  let iam = await Karma.accounts['test-acc'];
  let info = await Karma.db.get_full_accounts([iam.id],false);
  
  console.log(info)
}

Karma in REPL

If you install karmachan-package in global storage, you may start karma exec script:

$ karma
>|

This command try autoconnect to mainnet karmachain. If you want to connect on testnet, try this:

$ karma --testnet
>|

It is nodejs REPL with several variables:

  • karma, main class karmachain package
  • login, function to create object of class Karma
  • generateKeys, to generateKeys from login and password
  • accounts, is analog Karma.accounts
  • assets, is analog Karma.assets
  • db, is analog Karma.db
  • history, is analog Karma.hostory
  • network, is analog Karma.network
  • fees, is analog Karma.fees

For example

$ karma
> assets["krm"].then(console.log)

Shot request

If need call only one request, you may use --account, --asset, --block, --object, --history, --balance or --transfer keys in command-line:

$ karma --account <'name' or 'id' or 'last number in id'>
{
  "id": "1.2.5992",
  "membership_expiration_date": "1970-01-01T00:00:00",
  "registrar": "1.2.37",
  "referrer": "1.2.21",
  ...
}

$ karma --asset <'symbol' or 'id' or 'last number in id'>
{
  "id": "1.3.0",
  "symbol": "KRM",
  "precision": 5,
  ...
}

$ karma --block [<number>]
block_num: 4636380
{
  "previous": "0046bedba1317d146dd6afbccff94412d76bf094",
  "timestamp": "2018-10-01T13:09:40",
  "witness": "1.6.41",
  ...
}

$ karma --object 1.2.3
{
  "id": "1.2.3",
  "membership_expiration_date": "1969-12-31T23:59:59",
  "registrar": "1.2.3",
  "referrer": "1.2.3",
  ...
}

$ karma --history <account> [<limit>] [<start>] [<stop>]
[
  {
    "id": "1.11.98179",
    "op": [
      0,
  ...
}]

$ karma --balance <account or accounts> [<asset or assets>]
account
KRM: 1234.567

$ karma --transfer <from> <to> <amount> <asset> [--key]
Transfered <amount> <asset> from '<from>' to '<to>' with memo '<memo>'

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The package is available as open source under the terms of the MIT License.

karmachain's People

Contributors

scientistnik avatar

Watchers

James Cloos avatar  avatar KazFan29 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.