The @hoprnet/hopr-sdk
package is a software development kit for interacting with HOPRd's Rest API functions.
It provides a set of functions that allow developers to interact with the HOPR protocol and perform various actions such as node and account management, messaging, address retrieval, balance retrieval, and withdrawal and other operations.
To install the @hoprnet/hopr-sdk
package, follow these steps:
- Make sure you have node.js >=16 installed on your machine.
- Open your terminal or command prompt.
- Navigate to your project directory.
- Run the following command to install the package using:
npm install @hoprnet/hopr-sdk
or
yarn add @hoprnet/hopr-sdk
You can use the @hoprnet/hopr-sdk
in two different ways:
By creating a new instance of the HoprSDK class.
- Import the HoprSDK class from the package:
import { HoprSDK } from '@hoprnet/hopr-sdk';
- Create an instance of the HoprSDK class by providing the required parameters:
const sdk = new HoprSDK({
apiEndpoint: 'http://localhost:3001', // Replace with your HOPR API endopoint.
apiToken: 'your-api-token', // Replace with your API token
timeout: 5000 // Optional timeout in milliseconds (defaults to 30000)
});
- You can now use the
sdk
instance to access the available functions. For example, to get the HOPR and native addresses associated with the node:
const addresses = await sdk.api.account.getAddresses();
console.log(addresses);
By calling directly the rest API functions.
- Import the API object from the package:
import { api } from '@hoprnet/hopr-sdk';
- If your ts config includes
"moduleResolution": "nodenext" or "node16"
, you can import the functions like this:
import { getAddresses } from '@hoprnet/hopr-sdk/api';
- Access the desired function, keep in mind that you'll need to provide a payload object with the
apiEndpoint
andapiToken
for each individual function:
const addresses = await api.getAddresses({
apiEndpoint: 'http://localhost:3001', // Replace with your HOPR API endopoint
apiToken: 'your-api-token' // Replace with your API token
timeout: 5000 // Optional timeout in milliseconds (defaults to 30000)
});
console.log(addresses);
By calling directly the flows functions.
- Import the flows object from the package:
import { flows } from '@hoprnet/hopr-sdk';
- If your ts config includes
"moduleResolution": "nodenext" or "node16"
, you can import the functions like this:
import { openMultipleChannels } from '@hoprnet/hopr-sdk/flows';
- Access the desired function, keep in mind that you'll need to provide a payload object with the
apiEndpoint
andapiToken
for each individual function:
const res = await flows.openMultipleChannels({
apiEndpoint: 'http://localhost:3001', // Replace with your HOPR API endopoint
apiToken: 'your-api-token' // Replace with your API token
timeout: 60e3 * 7 // Optional timeout in milliseconds (defaults to 30000) | This function takes really long
});
console.log(res);