Constructing a Wax interface
The root Wax interface can be constructed using either default or custom configuration options. Custom options allow selecting a specific blockchain network (e.g. mainnet, testnet, or mirrornet), a specific Hive API endpoint (e.g. api.hive.blog) and also a custom REST API endpoint. It also provides settings to optimize for performance, network latency, or other custom needs.
Default Wax initialization
Test it yourself: src/typescript/config/init-general/chain.ts
import { createHiveChain } from '@hiveio/wax';
// Initialize Hive Chain using default options
await createHiveChain();
Test it yourself on github codespace: src/python/default_wax_initialization.py
from wax import WaxChainOptions, WaxOptions, create_hive_chain, create_wax_foundation
wax = create_wax_foundation()
wax_custom_options = create_wax_foundation(
options=WaxOptions(chain_id="f875a0b000000000000000000000000000000000000000000000000000000000")
)
Test it yourself on github codespace: src/rust/config/init_general/chain.rs
use wax::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize Hive Chain using default options
create_hive_chain(None)?;
Ok(())
}
Initializing Wax interface with custom options
Test it yourself: src/typescript/config/init-general/chain-with-config.ts
import { createHiveChain, IWaxOptionsChain } from '@hiveio/wax';
// Define custom options
const customOptions: IWaxOptionsChain = {
// Example custom chain ID:
chainId: 'f875a0b000000000000000000000000000000000000000000000000000000000',
// Example custom API endpoint:
apiEndpoint: 'https://hive.custom.endpoint',
// Example custom REST API endpoint:
restApiEndpoint: 'https://rest.api.custom.endpoint',
// Disable API timeout:
apiTimeout: 0
};
// Initialize Hive Chain with custom options
const chain = await createHiveChain(customOptions);
Test it yourself on github codespace: src/python/default_wax_initialization.py
from wax import WaxChainOptions, WaxOptions, create_hive_chain, create_wax_foundation
wax_chain = create_hive_chain(
options=WaxChainOptions(
chain_id="beeab0de00000000000000000000000000000000000000000000000000000000", # mainnet chain ID
endpoint_url="https://api.hive.blog", # public mainnet API node
)
)
Test it yourself on github codespace: src/rust/config/init_general/chain_with_config.rs
use wax::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Define custom options
let custom_options = HiveChainOptions {
// Example custom chain ID:
chain_id: "f875a0b000000000000000000000000000000000000000000000000000000000"
.into(),
// Example custom API endpoint:
api_endpoint: "https://hive.custom.endpoint".into(),
// Example custom REST API endpoint:
rest_api_endpoint: "https://rest.api.custom.endpoint".into(),
// Disable API timeout:
api_timeout: 0,
// Keep the defaults for everything else:
..Default::default()
};
// Initialize Hive Chain with custom options
let _chain = create_hive_chain(custom_options)?;
Ok(())
}