JSPM

@stacks/network

2.0.1-beta.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 134251
  • Score
    100M100P100Q215268F
  • License GPL-3.0-or-later

Library for Stacks network operations

Package Exports

  • @stacks/network

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stacks/network) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@stacks/network

Network and API library for working with Stacks blockchain nodes.

Installation

npm install @stacks/network

Usage

Creating a Stacks mainnet, testnet, regtest or mocknet network

import { StacksMainnet, StacksTestnet, StacksMocknet } from '@stacks/network';

const network = new StacksMainnet();

const testnet = new StacksTestnet();

const regtest = new StacksRegtest();

const mocknet = new StacksMocknet();

Setting a custom node URL

network.coreApiUrl = 'https://www.mystacksnode.com/';

Check if network is mainnet

const isMainnet = network.isMainnet();

Example usage in transaction builder

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

const txOptions = {
  network,
  recipient: 'SP2BS6HD7TN34V8Z5BNF8Q2AW3K8K2DPV4264CF26',
  amount: new BigNum(12345),
  senderKey: 'b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01',
};

const transaction = await makeSTXTokenTransfer(txOptions);

Get various API URLs

  const txBroadcastUrl = network.getBroadcastApiUrl();

  const feeEstimateUrl = network.getTransferFeeEstimateApiUrl();

  const address = 'SP2BS6HD7TN34V8Z5BNF8Q2AW3K8K2DPV4264CF26';
  const accountInfoUrl = network.getAccountApiUrl(address);

  const contractName = 'hello_world';
  const abiUrl = network.getAbiApiUrl(address, contractName);

  const functionName = 'hello';
  const readOnlyFunctionCallUrl = network.getReadOnlyFunctionCallApiUrl(address, contractName, functionName);

  const nodeInfoUrl = network.getInfoUrl();

  const blockTimeUrl = network.getBlockTimeInfoUrl();

  const poxInfoUrl = network.getPoxInfoUrl();