npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@helium/http

v4.12.1-alpha.0

Published

HTTP library for interacting with the Helium blockchain API

Downloads

841

Readme

@helium/http

npm

An HTTP client for interfacing with the Helium blockchain. For more documentation on the underlying REST API, see the section on the Helium Developer Site.

Installation

$ yarn add @helium/http
# or
$ npm install @helium/http

Usage

Initializing the Client

By default, the client will be initialized with the production network: https://api.helium.io

import { Client } from '@helium/http'
const client = new Client()
client.network.endpoint //= https://api.helium.io/v1

To specify a specific network, such as staging, the client can be initialized with a Network instance

import { Client, Network } from '@helium/http'
const client = new Client(Network.staging)
client.network.endpoint //= https://api.helium.wtf/v1
Available Networks

| Network | Base URL | Version | |----------------------|--------------------------|---------| | Network.production | https://api.helium.io | v1 | | Network.staging | https://api.helium.wtf | v1 |

Paginating Results

Automatic Pagination

Resource lists implement an asynchronous iterator, which allows for paginating over the whole collection while abstracting the underlying pages and cursors. This is great for an infinite scrolling UI, for example.

The asynchronous iterator can be used directly via the for-await-of syntax:

for await (const account of client.accounts.list()) {
  account //= Account
  // do something with account

  // after some condition is met, stop iterating
  if (someConditionMet)
    break
}

There is also a helper, take, which returns the items in chunks:

const list = await client.accounts.list()

await list.take(20) //= first 20 accounts
await list.take(20) //= next 20 accounts

Manual Pagination

If you're on an older version of Node.js or simply want to use the built-in pagination directly, the following methods are provided:

  const firstPage = await client.accounts.list()
  firstPage.data //= [Account, Account, ...]
  firstPage.hasMore //= true

  const nextPage = await firstPage.nextPage()
  firstPage.data //= [Account, Account, ...]
  firstPage.hasMore //= false

Resources

Accounts

Get an Account
await client.accounts.get('an-account-address')
List Accounts
await client.accounts.list()
Get an Accounts Stats
await client.accounts.getStats('an-account-address')

Blocks

Get a Block
// get by block height
await client.blocks.get(12345)

// alternatively get by block hash
await client.blocks.get('a-block-hash')
List Blocks
await client.blocks.list()
Current Block Height
await client.blocks.getHeight()

Stats

Get Network Stats
await client.stats.get()

Transactions

Get Transaction Activity for an Account
await client.account('an-account-address').activity.list()

// optionally filter by transaction types
await client.account('an-account-address').activity.list({
  filterTypes: ['payment_v1' ]
})
Get Transactions from a Block
// inititalize block by height
const block = await client.blocks.get(12345)

// alternatively initialize block by hash
const block = await client.blocks.get('fake-hash')

await block.transactions.list()
Submit a New Transaction
const serializedTxn = 'a-base64-serialized-txn'
const pendingTxn = await client.transactions.submit(serializedTxn)
pendingTxn //= PendingTransaction

See @helium/transactions for instructions on constructing a serialized transaction.

Pending Transactions

Check Status of Pending Transaction

This returns a ResourceList of pending transactions. In the case that a transaction fails and is submitted again it will return multiple pending transactions.

const pendingTxnsList = await client.pendingTransactions.get('fake-pending-txn-hash')
pendingTxns = await pendingTxnsList.take(100)
List Pending Transactions for an Account
const list = await client.account('fake-address').pendingTransactions.list()
const pendingTxns = await list.take(10)
pendingTxns //= [PendingTransacion]

Election Groups

Get an Election Group
await client.elections.get('hash')
List Election Groups
const list = await client.elections.list()
const elections = await list.take(10)

Price Oracle

Get the Current Oracle Price
await client.oracle.getCurrentPrice()

Cities

List all cities with hotspots
const list = await client.cities.list()
const cities = await list.take(10)
Search for a city
const list = await client.cities.list({ query: 'san francisco' })
const cities = await list.take(10)
Get specific city data
const city = await client.cities.get('city-id')
List hotspots in a city
const list = await client.city('city-id').hotspots.list()
const hotspots = await list.take(10)