Prerequisites
Before you begin, make sure you have:- Node.js 20 or higher installed
- hive-tx package installed (see installation)
- A Hive account with a private key (posting key for voting, active key for transfers)
Your first transaction
1
Import the required modules
Start by importing the
Transaction and PrivateKey classes from hive-tx:2
Create a transaction and add an operation
Create a new transaction instance and add a vote operation:
The
addOperation method is asynchronous because it fetches blockchain data to set up the transaction properly.3
Sign the transaction
Sign the transaction with your private posting key:
4
Broadcast to the network
Broadcast the signed transaction to the Hive blockchain:
The
Example output
Example output
status will be "unknown" by default. Pass true to broadcast() to wait for confirmation:Complete example
Here’s the complete code in one place:Transfer example
Here’s how to send HIVE or HBD tokens:Amount must be formatted as a string with 3 decimal places:
"1.000 HIVE" or "5.123 HBD"Making API calls
Query blockchain data without broadcasting transactions:Error handling
Always wrap your code in try-catch blocks to handle errors:Next steps
Now that you’ve created your first transaction, explore more features:Transactions
Learn about transaction structure and lifecycle
Operations
Explore all available Hive operations
Key Management
Generate and manage keys securely
Examples
See more real-world examples