项目作者: dtube

项目描述 :
javascript module for communicating with avalon api
高级语言: JavaScript
项目地址: git://github.com/dtube/javalon.git
创建时间: 2019-04-13T16:25:12Z
项目社区:https://github.com/dtube/javalon

开源协议:

下载


Javalon

Install

Require style

Install with npm install --save javalon inside your project. Then just

  1. const javalon = require('javalon')

CDN style

If you are working in the browser and want to load javalon from a CDN:

  1. <script src="https://unpkg.com/javalon/bin/javalon.min.js"></script>

By default, javalon hits on the main avalon testnet (https://avalon.d.tube). You can eventually make javalon hit on your local node or any avalon node like so:

  1. javalon.init({api: 'http://localhost:3001'})

GET API

GET single account

  1. javalon.getAccount('alice', (err, account) => {
  2. console.log(err, account)
  3. })

GET many accounts

Just pass an array of usernames instead

  1. javalon.getAccounts(['alice', 'bob'], (err, accounts) => {
  2. console.log(err, accounts)
  3. })

GET account transaction history

For the history, you also need to specify a block number. The api will return all blocks lower than the specified block where the user was involved in a transaction

  1. javalon.getAccountHistory('alice', 0, (err, blocks) => {
  2. console.log(err, blocks)
  3. })

GET single content

  1. javalon.getContent('alice', 'pocNl2YhZdM', (err, content) => {
  2. console.log(err, content)
  3. })

GET followers

  1. javalon.getFollowers('alice', (err, followers) => {
  2. console.log(err, followers)
  3. })

GET following

  1. javalon.getFollowers('alice', (err, followers) => {
  2. console.log(err, followers)
  3. })

GET contents by author

You can pass a username and permlink (identifying a content) in the 2nd and 3rd argument to ‘get more’.

  1. javalon.getDiscussionsByAuthor('alice', null, null, (err, contents) => {
  2. console.log(err, contents)
  3. })

GET contents by creation time

You can pass a username and a permlink to ‘get more’.

  1. javalon.getNewDiscussions('alice', null, null, (err, contents) => {
  2. console.log(err, contents)
  3. })

GET contents by popularity (hot)

You can pass a username and a permlink to ‘get more’.

  1. javalon.getHotDiscussions(null, null, (err, contents) => {
  2. console.log(err, contents)
  3. })

GET contents by feed

This lists the contents posted by the following of the passed username.

You can pass a username and a permlink in the 2nd and 3rd argument to ‘get more’.

  1. javalon.getFeedDiscussions('alice', null, null, (err, contents) => {
  2. console.log(err, contents)
  3. })

GET notifications

  1. javalon.getNotifications('alice', (err, contents) => {
  2. console.log(err, contents)
  3. })

GET all votes by account

  1. javalon.getVotesByAccount('alice', 0, (err, votes) => {
  2. console.log(err, votes)
  3. })

GET pending votes by account

  1. javalon.getPendingVotesByAccount('alice', 0, (err, votes) => {
  2. console.log(err, votes)
  3. })

GET claimable votes by account

  1. javalon.getClaimableVotesByAccount('alice', 0, (err, votes) => {
  2. console.log(err, votes)
  3. })

GET claimed votes by account

  1. javalon.getClaimedVotesByAccount('alice', 0, (err, votes) => {
  2. console.log(err, votes)
  3. })

GET pending rewards by account

  1. javalon.getPendingRewards('alice', (err, votes) => {
  2. console.log(err, votes)
  3. })

GET claimed rewards by account

  1. javalon.getClaimedRewards('alice', (err, votes) => {
  2. console.log(err, votes)
  3. })

GET claimable rewards by account

  1. javalon.getClaimableRewards('alice', (err, votes) => {
  2. console.log(err, votes)
  3. })

POST API

To send a transaction to the network, you will need multiple steps. First you need to define your transaction and sign it.

  1. var newTx = {
  2. type: javalon.TransactionType.FOLLOW,
  3. data: {
  4. target: 'bob'
  5. }
  6. }
  7. newTx = javalon.sign(alice_key, 'alice', newTx)

After this step, the transaction is forged with a timestamp, hash, and signature. This transaction needs to be sent in the next 60 secs or will be forever invalid.

You can send it like so

  1. javalon.sendTransaction(newTx, function(err, res) {
  2. cb(err, res)
  3. })

The callback will return once your transaction has been included in a new block.

Alternatively, you can just want the callback as soon as the receiving node has it, you can do:

  1. javalon.sendRawTransaction(newTx, function(err, res) {
  2. cb(err, res)
  3. })

Convenience

Generate a keypair

  1. console.log(javalon.keypair())

Growing variables

Voting Power and Bandwidth are growing in time but the API will only return the latest update in the vt and bw fields of the accounts. To get the actual value, use votingPower() and bandwidth()

  1. javalon.getAccount('alice', (err, account) => {
  2. console.log(javalon.votingPower(account))
  3. console.log(javalon.bandwidth(account))
  4. })