[v7.0.0] Hive-tx - JavaScript/TypeScript library for Hive Blockchain

in HiveDevs8 days ago

hive-tx-v7.png

This is a technical post for developers.

What is hive-tx? It is a lightweight and complete TypeScript/JavaScript toolkit for building on Hive with minimal dependencies.


v7.0.0

Added more features but also reduced the overall size of the library. I'll add more QoL features going forward. But for now, I think this is a good place for a stable release.

The highlight of the new version for me is callWithQuorum() which cross-checks the API result with multiple nodes. Trusting one single public node in sensitive tasks is a bit risky. With this, your confidence in the data can be quite high. The function rotates the nodes and calls random nodes every time and return the result once enough nodes (passed as quorum to function) agree on the result. By default quorum is 2. Meaning two nodes must agree on the result.

Example call:

const accounts = await callWithQuorum('condenser_api.get_accounts', [['username']], 2)
console.log('Account:', result[0])

Hopefully I will be able to maintain and improve this library further. There have been a lot of changes that can break the older apps. v7.0.0 requires node version 20+. So test and let me know. Feature requests are welcome.

Here is the rough list of the changes:

Major Changes

Complete TypeScript rewrite of the library with significant API improvements and breaking changes.

Added

  • TypeScript Support: Complete rewrite in TypeScript with full type definitions
  • Type-Safe Operations: Added comprehensive types for all 46 Hive blockchain operations
  • JSDoc Documentation: All methods now include detailed JSDoc comments
  • New API Methods:
    • callRPC(): Simplified JSON-RPC calls with automatic retry and failover
    • callREST(): Type-safe REST API calls with full endpoint typing
    • callWithQuorum(): Cross-check results with multiple nodes for enhanced reliability (JSON-RPC call)
  • Enhanced Transaction API:
    • Transaction.addOperation(): New async method for adding operations
    • Transaction.checkStatus(): Check transaction status after broadcasting
    • Support for checkStatus parameter in broadcast() to wait for block inclusion
  • Multiple Build Targets:
    • ES Module (ESM) build with source maps and declarations
    • CommonJS (CJS) build for Node.js compatibility
    • Browser UMD build (minified, ~29KB gzipped)
  • Comprehensive Testing:
    • Operation tests validating transaction serialization
    • Coverage tests for all major functionality
    • Automated testing against live Hive blockchain
  • Enhanced Documentation:
    • docs/QUICKSTART.md: Quick start guide for beginners
    • docs/EXAMPLES.md: Comprehensive usage examples
    • Updated README with clear examples and migration guide

Changed

  • Breaking: tx.create() replaced with await tx.addOperation(opName, opBody)
  • Breaking: call() replaced with callRPC() - returns result directly instead of JSON-RPC wrapper
  • Breaking: callRPC() now throws RPCError on errors instead of returning {error}
  • Breaking: Transaction.broadcast(timeout?, retry?) signature changed to Transaction.broadcast(checkStatus?)
  • Breaking: All timeout values changed from seconds to milliseconds
  • Breaking: All expiration values changed from seconds to milliseconds
  • Breaking: new Transaction(transaction) constructor changed to new Transaction({transaction, expiration})
  • Breaking: config.node (string) changed to config.nodes (array)
  • Breaking: Removed Transaction.signedTransaction - signatures now available on Transaction.transaction
  • Breaking: Removed config.healthcheckInterval
  • Improved: Better error messages and error handling throughout

https://github.com/mahdiyari/hive-tx
https://www.npmjs.com/package/hive-tx

Consider giving a star on GitHub repository ;P

Sort:  

Congratulations @mahdiyari! Your post has been a top performer on the Hive blockchain and you have been rewarded with this rare badge

Post with the highest payout of the day.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Our Hive Power Delegations to the November PUM Winners
Feedback from the December Hive Power Up Day
Hive Power Up Month Challenge - November 2025 Winners List