Skip to main content Link Search Menu Expand Document (external link)

Usage

Initialization

To start the client, just instantiate the HubAPI class by passing it the URL of the Nimiq Hub to connect to:

// Connect to testnet
const hubApi = new HubApi('https://hub.nimiq-testnet.com');

// Connect to mainnet
const hubApi = new HubApi('https://hub.nimiq.com');

Calling Methods

Call an API method on your HubApi instance in the context of a user action:

document.getElementById('checkoutBtn').addEventListener('click', function(event) {
  // Call the API here:
  hubApi.checkout({ /* options */ });
});

By default, the client opens a popup window for user interactions. On mobile devices, a new tab will be opened instead. For simplicity, we will always refer to popups throughout this documentation.

Popups will be blocked by browsers if not opened within the context of a user action. Thus, it is required that API methods are called synchronously within a user action, such as a click.

For more details about avoiding popup blocking, please refer to this article.

Using Redirects

Please refer to the Using Redirects section.


Next: API Reference