Skip to main content
The WAX factory functions provide entry points to create instances for working with the Hive blockchain. Use createWaxFoundation() for offline operations and createHiveChain() for full chain access.

createWaxFoundation

Creates a WAX foundation instance for offline operations including transaction building, signing, and validation.
import { createWaxFoundation } from '@hiveio/wax';

const wax = await createWaxFoundation({
  chainId: "beeab0de00000000000000000000000000000000000000000000000000000000"
});

Parameters

options
Partial<IWaxOptions>
default:"{}"
Optional configuration for the WAX instance

Returns

Promise<IWaxBaseInterface>
Promise<IWaxBaseInterface>
Promise that resolves to a WAX base interface instance

Usage example

import { createWaxFoundation } from '@hiveio/wax';

// Create WAX foundation instance
const wax = await createWaxFoundation();

// Create a transaction
const tx = wax.createTransactionWithTaPoS(
  "0000000000000000000000000000000000000000",
  "+1m"
);

// Add operations
tx.pushOperation({
  vote: {
    voter: "alice",
    author: "bob",
    permlink: "example-post",
    weight: 10000
  }
});

// Get transaction JSON
const txJson = tx.toApi();
console.log(txJson);

Error handling

WaxError
Error
Throws WaxError on any WAX API-related error during initialization

createHiveChain

Creates a WAX Hive chain instance with full chain access including API calls and transaction broadcasting.
import { createHiveChain } from '@hiveio/wax';

const chain = await createHiveChain({
  apiEndpoint: "https://api.hive.blog",
  chainId: "beeab0de00000000000000000000000000000000000000000000000000000000"
});

Parameters

options
Partial<IWaxOptionsChain>
default:"{}"
Optional configuration for the Hive chain instance

Returns

Promise<IHiveChainInterface>
Promise<IHiveChainInterface>
Promise that resolves to a Hive chain interface instance with full API access

Usage example

import { createHiveChain } from '@hiveio/wax';

// Create Hive chain instance
const chain = await createHiveChain({
  apiEndpoint: "https://api.hive.blog",
  apiTimeout: 5000
});

// Get dynamic global properties
const dgpo = await chain.api.database_api.get_dynamic_global_properties({});
console.log('Head block:', dgpo.head_block_number);

// Create transaction with automatic TAPOS
const headBlockId = dgpo.head_block_id;
const tx = chain.createTransactionWithTaPoS(headBlockId);

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

// Sign and broadcast (requires signature provider)
// const signature = await signer.signTransaction(tx.sigDigest);
// tx.addSignature(signature);
// await chain.api.network_broadcast_api.broadcast_transaction({ trx: tx.toApiJson() });

Error handling

WaxError
Error
Throws WaxError on any WAX API-related error during initialization

TypeScript types

IWaxOptions

interface IWaxOptions extends IWaxBaseExtendibleOptions {
  wasmLocation?: string;
}

interface IWaxBaseExtendibleOptions {
  chainId: THexString;
}

IWaxOptionsChain

interface IWaxOptionsChain extends IWaxOptions, IWaxChainExtendibleOptions {}

interface IWaxChainExtendibleOptions extends IWaxBaseExtendibleOptions {
  apiEndpoint: string;
  restApiEndpoint: string;
  waxApiCaller?: string;
  apiTimeout: number;
}

Default options

// Default WAX options
const DEFAULT_WAX_OPTIONS: IWaxOptions = {
  chainId: "beeab0de00000000000000000000000000000000000000000000000000000000"
};

// Default chain options
const DEFAULT_WAX_OPTIONS_CHAIN: IWaxOptionsChain = {
  ...DEFAULT_WAX_OPTIONS,
  apiEndpoint: "https://api.hive.blog",
  restApiEndpoint: "https://api.syncad.com",
  apiTimeout: 2000,
  waxApiCaller: undefined
};

See also

Build docs developers (and LLMs) love