Skip to main content
Version: v2.08

Code Snippets for HOPR Apps

Common Functions

Most HOPR applications require to do at least one of the following actions:

  • Send commands to a HOPR node REST API via an Authenticated request
  • Connect to a WebSocket HOPR and listen to responses sent there
  • Prompt users for the HOPR node HTTP and WebSocket endpoints and API token

Since these actions are usually cumbersome, we have generated a few code snippets developers can copy and paste to execute most of these actions quickly. These snippets will eventually be included in an SDK1, but for the time being, having them here is the easiest and fastest way for anyone to get started.


useWebSocket.js

Loading useWebSocket.js


WebSocketHandler.jsx

Loading WebSocketHandler.jsx


getHeaders.js

Loading getHeaders.js

API Example Use

Here are some examples of how to use HOPR APIs with your terminal, Python or JS. HOPR is code agnostic so any language would work, you could even use API platforms like Postman to interact with your HOPR node.

accountWithdraw

curl -X POST http://YOUR_API_URL:3001/api/v2/account/withdraw \
-H "Content-Type: application/json" \
-H "x-auth-token: YOUR_API_KEY" \
-d '{"amount": "1000000000000000000", "currency": "HOPR", "recipient": "YOUR_WALLET_ADDRESS"}'

accountBalances

curl -X GET http://YOUR_API_URL:3001/api/v2/account/balances \
-H "x-auth-token: YOUR_API_KEY"

accountAddresses

curl -X GET http://YOUR_API_URL:3001/api/v2/account/addresses \
-H "x-auth-token: YOUR_API_KEY"

Get Aliases

curl -X GET http://YOUR_API_URL:3001/api/v2/aliases \
-H "x-auth-token: YOUR_API_KEY"

Set Alias

curl -X POST http://YOUR_API_URL:3001/api/v2/aliases \
-H "x-auth-token: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"peerId": "16Uiu2HAmUsJwbECMroQUC29LQZZWsYpYZx1oaM1H9DBoZHLkYn12", "alias": "Alice"}'

channelsRedeemTickets

curl -X POST http://YOUR_API_URL:3001/api/v2/channels/tickets/redeem \
-H "Content-Type: application/json" \
-H "x-auth-token: YOUR_API_KEY"

channelsGetTickets

curl -X GET http://YOUR_API_URL:3001/api/v2/channels/tickets \
-H "Content-Type: application/json" \
-H "x-auth-token: YOUR_API_KEY"

channelsCloseChannel

curl -X DELETE http://YOUR_API_URL:3001/api/v2/channels \
-H "Content-Type: application/json" \
-H "x-auth-token: YOUR_API_KEY"

  1. To get updates on the progress of our SDK, please subscribe to this issue.