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 Chain ID in hex string format. Defaults to mainnet chain ID.
Path to the WASM file. Can be a relative path or absolute URL. If not specified, uses default path: "./build_wasm/wax.common.wasm" (may change if bundled). You can also specify a base64 encoded string of the WASM file for inlining. Bundler examples:
Vite: import wasmUrl from './my_wasm_files/wax.common.wasm?url';
Webpack: const wasmUrl = new URL("./my_wasm_files/wax.common.wasm", import.meta.url).href;
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
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 Chain ID in hex string format
apiEndpoint
string
default: "https://api.hive.blog"
Endpoint for all JSON-RPC API requests
restApiEndpoint
string
default: "https://api.syncad.com"
Endpoint for all REST API requests
Timeout for all API requests in milliseconds. Set to 0 to disable timeout.
X-Wax-Api-Caller header value for all requests (both API and REST API). This header identifies the application making requests. If not set, the header will not be sent.
Path to the WASM file (same as createWaxFoundation)
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
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