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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stacks/network

v7.7.0

Published

Library for Stacks network operations

Downloads

1,021,552

Readme

@stacks/network

Network configuration for Stacks.js.

This package defines which chain and which node the other @stacks/* packages talk to. A network is a plain data object. It is not a class. It holds constants (chain id, transaction version, address versions) and a static client instance with the node URL.

The network is a plain object on purpose. You can serialize it, copy it, and override single fields.

Installation

npm install @stacks/network

Usage

Use a network

In most cases the string name is enough. Every function that accepts a network accepts 'mainnet', 'testnet', or 'devnet'.

import { makeSTXTokenTransfer } from '@stacks/transactions';

const tx = await makeSTXTokenTransfer({
  // ...
  network: 'testnet',
});

The exported constants hold the full network objects. Use them when you want the object itself.

import { STACKS_MAINNET, STACKS_TESTNET, STACKS_DEVNET } from '@stacks/network';

const tx = await makeSTXTokenTransfer({
  // ...
  network: STACKS_TESTNET,
});

Customize a network

Use createNetwork to set an API key or a custom node URL.

import { createNetwork } from '@stacks/network';

// Network name and API key
const network = createNetwork('mainnet', 'my-api-key');

// Options object
const network2 = createNetwork({ network: 'testnet', apiKey: 'my-api-key' });

// Custom node URL
const network3 = createNetwork({
  network: 'mainnet',
  client: { baseUrl: 'https://custom-api.example.com' },
});

createNetwork copies the base network. It does not mutate STACKS_MAINNET or the other constants.

The API key is sent as an x-api-key header. By default, the header is only sent to Hiro API hosts.

The network and client options

Functions in other packages accept the network and the client as separate options. The network selects the chain. The client selects the node URL and the fetch function.

import { broadcastTransaction } from '@stacks/transactions';

await broadcastTransaction({
  transaction,
  network: 'mainnet',
  client: { baseUrl: 'https://custom-api.example.com' }, // optional override
});

The network's own client is used by default. A client option overrides it, field by field.

The client object has two optional fields:

fetch is the only field of a network that is not serializable. It is also the extension point: bake middleware (authentication, retries, logging) into your fetch function.

On the exported constants, client.fetch is undefined. The consuming function creates a default fetch function when it needs one.

The network object

A StacksNetwork object has this shape:

interface StacksNetwork {
  chainId: number;
  transactionVersion: number;
  peerNetworkId: number;
  magicBytes: string;
  bootAddress: string;
  addressVersion: { singleSig: number; multiSig: number };
  client: { baseUrl: string; fetch?: FetchFn };
}

The constants ChainId, TransactionVersion, and AddressVersion are exported for code that reads these fields.

import { AddressVersion, ChainId, TransactionVersion } from '@stacks/network';

ChainId.Mainnet; // 0x00000001
TransactionVersion.Mainnet; // 0x00
AddressVersion.MainnetSingleSig; // 22