Overview
The WAX SDK uses a modular approach to API definitions. Rather than bundling all possible API endpoints in the core library, separate packages provide definitions for different services:- JSON-RPC APIs: Core Hive node APIs (database_api, network_broadcast_api, etc.)
- REST APIs: External services like HAF-based APIs
Available API packages
Here are the official API definition packages:JSON-RPC API
@hiveio/wax-api-jsonrpcFull JSON-RPC API definitions for Hive nodes.
HAF Block Explorer
@hiveio/wax-api-hafbeBlock Explorer REST API definitions.
Reputation Tracker
@hiveio/wax-api-reputation-trackerReputation tracking REST API definitions.
Balance Tracker
@hiveio/wax-api-balance-trackerAccount balance tracking API definitions.
Account History
@hiveio/wax-api-hafahHAF Account History REST API definitions.
Using JSON-RPC APIs
The JSON-RPC API package provides definitions for standard Hive node APIs.Installation
Basic usage
Available JSON-RPC APIs
The package includes definitions for:- database_api: Query blockchain data
- network_broadcast_api: Broadcast transactions
- block_api: Retrieve blocks and block data
- account_by_key_api: Find accounts by public key
- rc_api: Resource credit information
Using REST APIs
REST API packages provide definitions for external services built on HAF (Hive Application Framework).Installation
Install the REST API package you need:Basic usage
Creating custom API definitions
You can create your own API definitions for custom services:For JSON-RPC APIs
For REST APIs
API definition generator
WAX provides a tool to automatically generate API definitions from OpenAPI/Swagger specifications:Benefits of API packages
Type safety
Full TypeScript support with autocomplete and validation.
Smaller bundles
Only include the APIs you actually use.
Versioning
Independent versioning for each API package.
Custom APIs
Easy to add support for custom services.
Example: Multi-API application
Here’s an example using multiple API packages together:Best practices
Install only what you need
Install only what you need
Don’t install all API packages if you only use a few endpoints. Keep your bundle size small by installing only the packages you actually use.
Use type inference
Use type inference
Let TypeScript infer types from the API definitions rather than manually typing responses:
Cache API instances
Cache API instances
Extending the chain creates new instances. Cache the extended chain to avoid recreating it:
Next steps
API extensions guide
Learn more about extending APIs.
TypeScript examples
See complete examples using APIs.