Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/openhive-network/wax/llms.txt

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.

Creating a transaction

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.
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'
});
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.
// 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 });
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.
import { transfer } from '@hiveio/wax';

// Add a simple vote operation
tx.pushOperation({
  vote_operation: {
    voter: "alice",
    author: "bob",
    permlink: "example-post",
    weight: 10000 // 100% upvote
  }
});

// Add a transfer operation
tx.pushOperation({
  transfer_operation: {
    from_account: "alice",
    to_account: "bob",
    amount: chain.hive.satoshis(1), // 1 HIVE
    memo: "Thanks for the post!"
  }
});

// Chain multiple operations
tx.pushOperation({
  vote_operation: {
    voter: "alice",
    author: "carol",
    permlink: "another-post",
    weight: 5000 // 50% upvote
  }
}).pushOperation({
  comment_operation: {
    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.
// Set custom expiration (5 minutes from now)
const tx = await chain.createTransaction({
  expirationTime: "+5m"
});

// Or use a specific timestamp
const tx = wax.createTransaction({
  taposBlockId: blockId,
  expirationTime: "+1h"
});
5

Validate the transaction

Before signing, validate that your transaction is well-formed.
try {
  tx.validate();
  console.log('Transaction is valid!');
} catch (error) {
  console.error('Transaction validation failed:', error);
}
Always validate transactions before signing to catch errors early.

Transaction properties

Once you’ve built a transaction, you can access various properties:
// Get the transaction object
const protoTx = tx.transaction;

// Get transaction ID (after signing)
const txId = tx.id;

// Get signature digest for signing
const sigDigest = tx.sigDigest;

// Get impacted accounts
const accounts = tx.impactedAccounts;

// Get required authorities
const authorities = tx.requiredAuthorities;
console.log('Posting:', authorities.posting);
console.log('Active:', authorities.active);
console.log('Owner:', authorities.owner);

// Check if signed
const signed = tx.isSigned();

Converting transaction formats

WAX supports multiple transaction formats for interoperability:
// Convert to API JSON format
const apiJson = tx.toApiJson();

// Convert to legacy API format
const legacyJson = tx.toLegacyApi();

// Convert to binary
const binary = tx.toBinaryForm();

// Convert to string
const jsonString = tx.toString();

// Create from API JSON
const newTx = Transaction.fromApi(wax, apiJsonString);

Complete example

Here’s a complete example of building a transaction with multiple operations:
import { createHiveChain } from '@hiveio/wax';

async function buildTransaction() {
  // Initialize chain connection
  const chain = await createHiveChain();

  // Create transaction
  const tx = await chain.createTransaction();

  // Add multiple operations
  tx.pushOperation({
    vote_operation: {
      voter: "alice",
      author: "bob",
      permlink: "example-post",
      weight: 10000
    }
  }).pushOperation({
    transfer_operation: {
      from_account: "alice",
      to_account: "bob",
      amount: chain.hive.satoshis(1),
      memo: "Thanks!"
    }
  });

  // Validate before signing
  tx.validate();

  console.log('Transaction ID:', tx.id);
  console.log('Operations:', tx.transaction.operations.length);
  console.log('Impacted accounts:', Array.from(tx.impactedAccounts));

  return tx;
}

buildTransaction().catch(console.error);

Next steps

Signing transactions

Learn how to sign transactions with different providers

Broadcasting transactions

Send your signed transactions to the network

Complex operations

Use high-level operations for advanced workflows

Transaction API

Explore the full transaction API reference

Build docs developers (and LLMs) love