hive-tx v7
GitHub npm

Reference

API reference

Every public export and its signature. The type files in dist have the full types.

Exports

import {
  Transaction,
  PrivateKey,
  PublicKey,
  Signature,
  Memo,
  callRPC,
  callRPCBatch,
  callREST,
  callWithQuorum,
  RPCError,
  streamBlocks,
  streamBlockNumbers,
  streamOperations,
  config,
  utils
} from 'hive-tx'

import type {
  Operation,
  OperationName,
  OperationBody,
  TransactionType,
  BroadcastResult,
  TransactionStatus,
  Block,
  AppliedOperation
} from 'hive-tx'

Transaction

MemberType
constructor(options?){ transaction?, expiration? }
addOperation(name, body)Promise<void>
sign(keys)PrivateKey | PrivateKey[] → TransactionType
broadcast(checkStatus?)Promise<BroadcastResult>
checkStatus()Promise<TransactionStatus>
digest(){ digest: Uint8Array, txId: string }
addSignature(hex)130-character hex → TransactionType
transactionTransactionType | undefined
expirationmilliseconds, default 60000
BroadcastResult = {
  tx_id: string
  status: 'unknown' | 'within_irreversible_block' | 'expired_irreversible' | 'too_old'
}
TransactionStatus = {
  status: 'unknown' | 'within_mempool' | 'within_reversible_block' | 'within_irreversible_block'
    | 'expired_reversible' | 'expired_irreversible' | 'too_old'
}

PrivateKey

MemberType
PrivateKey.from(value)string | Uint8Array → PrivateKey
PrivateKey.fromString(wif)PrivateKey
PrivateKey.fromSeed(seed)string | Uint8Array → PrivateKey
PrivateKey.fromLogin(username, password, role?)role: 'owner' | 'active' | 'posting' | 'memo', default 'active'
PrivateKey.randomKey()PrivateKey
sign(hash)Uint8Array → Signature
createPublic(prefix?)PublicKey
getSharedSecret(publicKey)Uint8Array (64 bytes)
toString() / inspect()WIF / masked WIF

PublicKey

MemberType
PublicKey.from(value)string | PublicKey → PublicKey
PublicKey.fromString(key)PublicKey
verify(hash, signature)Uint8Array, Signature | string → boolean
toString() / toJSON()Key string with prefix

Signature

MemberType
Signature.from(hex)Signature
getPublicKey(hash)Uint8Array | string → PublicKey
customToString()130-character hex
toBuffer()Uint8Array

Memo

Memo.encode(privateKey, publicKey, memo): string
Memo.decode(privateKey, memo): string
Memo.encodeForAccount(privateKey, account, memo): Promise<string>

Calls

callRPC(method, params?, timeout?, retry?): Promise<T>
callRPCBatch(method, paramsList, timeout?, retry?): Promise<T[]>
callWithQuorum(method, params?, quorum?): Promise<T>
callREST(api, endpoint, params?, timeout?, retry?): Promise<typed response>

RPCError extends Error with code: number and data?: any.

Streams

streamBlocks({ from?, to? }): AsyncGenerator<Block>
streamBlockNumbers({ from?, to? }): AsyncGenerator<number>
streamOperations({ from?, to?, only_virtual? }): AsyncGenerator<AppliedOperation>

config

{
  nodes: string[]
  restNodes: string[]
  chain_id: string
  address_prefix: string
  timeout: number  // ms
  retry: number
}

utils

Async helpers take an account name or an account object you already fetched.

// Stake and price
parseAsset(asset): { amount: number, symbol: string }
vestsToHP(vests): Promise<number>
hpToVests(hp): Promise<number>
hiveToHbd(hive): Promise<number>
hbdToHive(hbd): Promise<number>
getEffectiveVests(account): Promise<number>

// Mana and votes
getVotingMana(account, now?): Promise<Manabar>
getDownvoteMana(account, now?): Promise<Manabar>
getRCMana(account, now?): Promise<Manabar>
getVoteRShares(account, weight?): Promise<number>
getVoteValue(account, weight?): Promise<number>
rsharesToHBD(rshares): Promise<number>
// Manabar = { current: number, max: number, percentage: number, fullAt: Date }

// Yield, value, reputation
getHpApr(): Promise<number>
getHbdApr(): Promise<number>
estimateAccountValue(account): Promise<number>
formatReputation(raw): number

// Keys
createPassword(): string
generateKeys(username, password): { privateKeys, publicKeys, owner, active, posting, memo_key }
isValidWif(wif): boolean
isValidPublicKey(key): boolean
getKeyRole(account, publicKey): Promise<'owner' | 'active' | 'posting' | 'memo' | null>
signMessage(message, privateKey): string
signImage(image, privateKey): string
verifyMessage(account, message, signature, role?): Promise<boolean>

// App authority: role is 'posting' (default) or 'active'
hasAccountAuthority(account, app, role?): Promise<boolean>
grantAccountAuthority(account, app, role?, weight?): Promise<['account_update2', body]>
revokeAccountAuthority(account, app, role?): Promise<['account_update2', body]>

// Social: each returns ['custom_json', body]
follow(follower, following)       unfollow(follower, following)
mute(follower, following)         unmute(follower, following)
blacklist(follower, following)    unblacklist(follower, following)
followBlacklist(follower, following)  unfollowBlacklist(follower, following)
followMuted(follower, following)      unfollowMuted(follower, following)
reblog(account, author, permlink)
subscribe(account, community)     unsubscribe(account, community)
delegateRC(from, delegatees, maxRc)

// Other
createPermlink(title?): string
commentOptions(author, permlink, options?): ['comment_options', body]
validateUsername(name): string | null
accountExists(name): Promise<boolean>
getProfile(account): Promise<Record<string, unknown>>
getRequiredRole(operation): 'posting' | 'active' | 'owner'
operations: Record<string, number>
makeBitMaskFilter(operationIds): filter arguments for get_account_history
buildWitnessSetProperties(owner, props): ['witness_set_properties', body]

Operation names

addOperation accepts every Hive operation name, and TypeScript checks the body against it. Common ones:

  • vote, comment, delete_comment, comment_options
  • transfer, transfer_to_vesting, withdraw_vesting, recurrent_transfer
  • custom_json, custom
  • delegate_vesting_shares, claim_reward_balance
  • account_update, account_update2, account_create, create_claimed_account
  • account_witness_vote, account_witness_proxy, witness_update, witness_set_properties

The full list is the Operation type in dist/index.d.mts, or src/types.ts on GitHub.

Support

Ask in #dev-chat on the Hive Discord server.