hive-tx v7
GitHub npm

Start

Quick start

Install the package. Create a vote. Call an API. Derive a key.

Install

npm install hive-tx --save
import { Transaction, PrivateKey, callRPC } from 'hive-tx'

Create a vote

  1. Create a Transaction object.
  2. Add a vote operation.
  3. Load the posting private key.
  4. Sign. Broadcast.
import { Transaction, PrivateKey } from 'hive-tx'

const tx = new Transaction()
await tx.addOperation('vote', {
  voter: 'guest123',
  author: 'guest123',
  permlink: '20191107t125713486z-post',
  weight: 9500
})

const privateKey = PrivateKey.from(
  '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg'
)
tx.sign(privateKey)
const result = await tx.broadcast()
console.log(result.tx_id)

weight 10000 is a 100 percent upvote. A negative weight is a downvote.

A vote needs the posting key. A transfer needs the active key. If one transaction mixes those operations, sign with both keys.

Create a transfer

const tx = new Transaction()
await tx.addOperation('transfer', {
  from: 'sender',
  to: 'receiver',
  amount: '1.000 HIVE',
  memo: 'Thanks'
})
tx.sign(PrivateKey.from('5J...active-key'))
const result = await tx.broadcast()
console.log(result.tx_id, result.status)

Call an API

import { callRPC } from 'hive-tx'

const accounts = await callRPC('condenser_api.get_accounts', [['mahdiyari']])
console.log(accounts[0].name, accounts[0].balance)

On RPC errors the function throws RPCError. It does not wrap the result in .result.

Create keys

import { PrivateKey, PublicKey } from 'hive-tx'

const key1 = PrivateKey.from('5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg')
const key2 = PrivateKey.randomKey()
const key3 = PrivateKey.fromLogin('username', 'password', 'posting')
const pub = key1.createPublic()
console.log(pub.toString())

More patterns are on the examples page.