Use this file to discover all available pages before exploring further.
Transactions are the fundamental way to interact with the Hive blockchain. This guide walks you through creating transactions from basic operations to complex multi-operation workflows.
Before you can build a transaction, you need to initialize a WAX instance. Use createWaxFoundation() for offline operations or createHiveChain() for online operations.
1
Initialize WAX
Choose between offline (foundation) and online (chain) modes based on your needs.
TypeScript
Python
import { createWaxFoundation, createHiveChain } from '@hiveio/wax';// For offline operations (transaction building, signing)const wax = await createWaxFoundation();// For online operations (API calls, broadcasting)const chain = await createHiveChain({ endpoint_url: 'https://api.hive.blog'});
from wax import create_wax_foundation, create_hive_chain# For offline operations (transaction building, signing)wax = create_wax_foundation()# For online operations (API calls, broadcasting)chain = create_hive_chain( endpoint_url='https://api.hive.blog')
Online mode automatically fetches chain configuration and head block data, making it easier to build transactions that will be broadcast.
2
Create a transaction
Create a transaction with TAPOS (Transaction as Proof of Stake) data. For online mode, this is handled automatically.
TypeScript
Python
// With online chain instance (recommended)const tx = await chain.createTransaction();// With offline foundation (requires TAPOS block ID)const blockId = '8e78947614be92e77f7db82237e523bdbd7a907b';const tx = wax.createTransaction({ taposBlockId: blockId });
# With online chain instance (recommended)tx = await chain.create_transaction()# With offline foundation (requires TAPOS block ID)block_id = '8e78947614be92e77f7db82237e523bdbd7a907b'tx = wax.create_transaction(tapos_block_id=block_id)
TAPOS (Transaction as Proof of Stake) references a recent block to prove the transaction was created for a specific chain, preventing replay attacks.
3
Add operations
Push one or more operations to your transaction. Operations represent actions on the blockchain.
from wax.proto.operations import vote, transfer, comment# Add a simple vote operationtx.push_operation( vote( voter="alice", author="bob", permlink="example-post", weight=10000 # 100% upvote ))# Add a transfer operationtx.push_operation( transfer( from_account="alice", to_account="bob", amount=chain.hive.satoshis(1), # 1 HIVE memo="Thanks for the post!" ))# Chain multiple operationstx.push_operation( vote( voter="alice", author="carol", permlink="another-post", weight=5000 # 50% upvote )).push_operation( comment( parent_author="carol", parent_permlink="another-post", author="alice", permlink="re-carol-another-post", title="", body="Great post!", json_metadata="{}" ))
You can add multiple operations to a single transaction. They will be executed in order.
4
Set expiration time (optional)
By default, transactions expire after 1 minute. You can customize this when creating the transaction.
TypeScript
Python
// Set custom expiration (5 minutes from now)const tx = await chain.createTransaction({ expirationTime: "+5m"});// Or use a specific timestampconst tx = wax.createTransaction({ taposBlockId: blockId, expirationTime: "+1h"});
from datetime import timedelta# Set custom expiration (5 minutes from now)tx = await chain.create_transaction( expiration_time=timedelta(minutes=5))
5
Validate the transaction
Before signing, validate that your transaction is well-formed.
Once you’ve built a transaction, you can access various properties:
TypeScript
Python
// Get the transaction objectconst protoTx = tx.transaction;// Get transaction ID (after signing)const txId = tx.id;// Get signature digest for signingconst sigDigest = tx.sigDigest;// Get impacted accountsconst accounts = tx.impactedAccounts;// Get required authoritiesconst authorities = tx.requiredAuthorities;console.log('Posting:', authorities.posting);console.log('Active:', authorities.active);console.log('Owner:', authorities.owner);// Check if signedconst signed = tx.isSigned();
# Get the transaction objectproto_tx = tx.transaction# Get transaction ID (after signing)tx_id = tx.id# Get signature digest for signingsig_digest = tx.sig_digest# Get impacted accountsaccounts = tx.impacted_accounts# Get required authoritiesauthorities = tx.required_authoritiesprint(f'Posting: {authorities.posting_accounts}')print(f'Active: {authorities.active_accounts}')print(f'Owner: {authorities.owner_accounts}')# Check if signedsigned = tx.is_signed
WAX supports multiple transaction formats for interoperability:
TypeScript
Python
// Convert to API JSON formatconst apiJson = tx.toApiJson();// Convert to legacy API formatconst legacyJson = tx.toLegacyApi();// Convert to binaryconst binary = tx.toBinaryForm();// Convert to stringconst jsonString = tx.toString();// Create from API JSONconst newTx = Transaction.fromApi(wax, apiJsonString);
# Convert to API JSON formatapi_json = tx.to_api_json()# Convert to legacy API formatlegacy_json = tx.to_legacy_api()# Convert to binarybinary = tx.to_binary_form()# Convert to stringjson_string = tx.to_string()# Create from API JSONnew_tx = Transaction.from_api(wax, api_json_string)