2.0.2 • Published 1 month ago

@hoprnet/hopr-sdk v2.0.2

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
1 month ago

@hoprnet/hopr-sdk

Description

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.

Installation

To install the @hoprnet/hopr-sdk package, follow these steps:

  1. Make sure you have node.js >=18 installed on your machine.
  2. Open your terminal or command prompt.
  3. Navigate to your project directory.
  4. Run the following command to install the package using:
npm install @hoprnet/hopr-sdk

or

yarn add @hoprnet/hopr-sdk

Usage

You can use the @hoprnet/hopr-sdk in two different ways:

HoprSDK class

By creating a new instance of the HoprSDK class.

  1. Import the HoprSDK class from the package:
import { HoprSDK } from '@hoprnet/hopr-sdk';
  1. 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)
});
  1. 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);

HOPR API functions

By calling directly the rest API functions.

  1. 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';
  1. Access the desired function, keep in mind that you'll need to provide a payload object with the apiEndpoint and apiToken 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);

HOPR Flows functions

By calling directly the flows functions.

  1. 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';
  1. Access the desired function, keep in mind that you'll need to provide a payload object with the apiEndpoint and apiToken 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);

Documentation

2.1.0-beta.28

1 month ago

2.1.0-beta.30

1 month ago

2.1.0-beta.27

1 month ago

2.1.0-beta.26

1 month ago

2.1.0-beta.25

1 month ago

2.1.0-beta.24

1 month ago

2.1.0-beta.23

1 month ago

2.1.0-beta.22

1 month ago

2.1.0-beta.21

1 month ago

2.1.0-beta.20

1 month ago

2.1.0-beta.19

1 month ago

2.0.2

2 months ago

2.1.0-beta.18

2 months ago

2.1.0-beta.17

3 months ago

2.1.0-beta.16

3 months ago

2.1.0-beta.15

3 months ago

2.1.0-beta.14

3 months ago

2.1.0-beta.13

3 months ago

2.1.0-beta.12

3 months ago

2.1.0-beta.11

3 months ago

2.1.0-beta.10

3 months ago

2.1.0-beta.7

3 months ago

2.1.0-beta.6

3 months ago

2.1.0-beta.9

3 months ago

2.1.0-beta.8

3 months ago

2.1.0-beta.5

3 months ago

2.1.0-beta.1

3 months ago

2.1.0-beta.0

3 months ago

2.1.0-beta.2

3 months ago

2.0.1

6 months ago

2.0.0

6 months ago

2.0.0-beta.11

7 months ago

2.0.0-beta.10

8 months ago

2.0.0-beta.9

8 months ago

2.0.0-beta.8

8 months ago

2.0.0-beta.7

8 months ago

2.0.0-beta.6

9 months ago

2.0.0-beta.5

9 months ago

2.0.0-beta.4

9 months ago

2.0.0-beta.3

9 months ago

2.0.0-beta.2

9 months ago

2.0.0-beta.1

9 months ago

0.0.1-alpha.14

9 months ago

0.0.1-alpha.12

10 months ago

0.0.1-alpha.11

10 months ago

0.0.1-alpha.10

11 months ago

0.0.1-alpha.9

11 months ago

0.0.1-alpha.8

11 months ago

0.0.1-alpha.7

11 months ago

0.0.1-alpha.6

11 months ago

0.0.1-alpha.5

11 months ago

0.0.1-alpha.4

12 months ago

0.0.1-alpha.3

12 months ago

0.0.1-alpha.2

12 months ago

0.0.1-alpha.1

12 months ago

0.0.1-alpha.0

12 months ago