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

@alexbosworth/blockchain

v3.2.0

Published

Blockchain data utility methods

Readme

Blockchain

Utility methods for working with Blockchain data

Methods

compactIntAsNumber

Convert a compact integer to a regular number

{
  encoded: <Compact Integer Encoded Number Buffer Object>
  [start]: <Buffer Offset Start Index Number>
}

@returns
{
  bytes: <Byte Count Number>
  number: <Integer Number>
}

Example:

const {compactIntAsNumber} = require('@alexbosworth/blockchain');

// Decode the plain number from the encoded compact int bytes
const {number} = compactIntAsNumber({encoded: Buffer.from('fdfd00', 'hex')});

componentsOfTransaction

Get the components of a hex-encoded transaction

{
  transaction: <Hex Encoded Transaction String>
}

@throws
<Error>

@returns
{
  inputs: [{
    id: <Spending Transaction Id Hex String>
    script: <ScriptSig Script Hex String>
    sequence: <Sequence Number>
    vout: <Spending Transaction Output Index Number>
    [witness]: [<Script Stack Element Hex String>]
  }]
  locktime: <Timelock nLockTime Number>
  outputs: [{
    script: <ScriptPub Script Hex String>
    tokens: <Tokens Count Number>
  }]
  version: <Version Number>
}

decodeBase58Address

Derive output hash and version data from a base58 address string

{
  address: <Base58 Encoded Address String>
}

@throws
<Error>

@returns
{
  hash: <Output Hash Buffer Object>
  version: <Script Version Byte Number>
}

decodeBech32Address

Decode a bech32 address string to derive the address details

{
  address: <Bech32 Encoded Address String>
}

@throws
<Error>

@returns
{
  data: <Output Data Buffer Object>
  prefix: <Human Readable Prefix String>
  version: <Witness Version Number>
}

idForBlock

Get an id for a block: the double sha256 hash of the block header

{
  block: <Hex Encoded Block Data String>
}

@throws
<Error>

@returns
{
  id: <Block Id Hex Encoded String>
}

idForTransaction

Derive the standard transaction id for a raw serialized tx

{
  transaction: <Hex Encoded Transaction String>
}

@throws
<Error>

@returns
{
  id: <Transaction Id Hex Encoded String>
}

idForTransactionComponents

Determine a transaction id from transaction components

Note: remember the input hash is the reversed byte order of a normal tx id

{
  inputs: [{
    hash: <Spending Internal Byte Order Transaction Id Buffer Object>
    script: <Script Buffer Object>
    sequence: <Sequence Number>
    vout: <Spending Transaction Output Index Number>
  }]
  locktime: <Timelock nLockTime Number>
  outputs: [{
    script: <Output Script Buffer Object>
    tokens: <Tokens Count Number>
  }]
  version: <Version Number>
}

@throws
<Error>

@returns
{
  id: <Transaction Id Hex String>
}

noLocktimeIdForTransaction

Get an id for a transaction with witness data and mlocktime not included

{
  buffer: <Data Buffer Object>
  [start]: <Starting Offset Index Number>
}

@throws
<Error>

@returns
{
  id: <No nLockTime Transaction Id Hex String>
}

numberAsCompactInt

Convert a number to compact size integer serialization

{
  number: <Amount to Convert to Compact Integer Serialization Number>
}

@throws
<Error>

@returns
{
  encoded: <Serialized Compact Integer Buffer Object>
}

p2pkhOutputScript

Get a Pay To Witness Public Key Hash Output Script

{
  hash: <Public Key Hash Buffer Object>
}

@throws
<Error>

@returns
{
  script: <Output Script Buffer Object>
}

p2shOutputScript

Get a Pay To Script Hash Output Script

{
  hash: <Script Hash Buffer Object>
}

@throws
<Error>

@returns
{
  script: <Output Script Buffer Object>
}

p2trOutputScript

Get a Pay To Taproot Output Script

{
  hash: <Taproot Hash Buffer Object>
}

@throws
<Error>

@returns
{
  script: <Output Script Buffer Object>
}

p2wpkhOutputScript

Get a Pay To Witness Public Key Hash Output Script

{
  hash: <Witness Public Key Hash Buffer Object>
}

@throws
<Error>

@returns
{
  script: <Output Script Buffer Object>
}

p2wshOutputScript

Get a Pay To Witness Script Hash Output Script

{
  hash: <Witness Script Hash Buffer Object>
}

@throws
<Error>

@returns
{
  script: <Output Script Buffer Object>
}

previousBlockId

Given a raw block, return the previous block id

{
  block: <Hex Encoded Block String>
}

@throws
<Error>

@returns
{
  previous: <Previous Block Id Hex String>
}

queryTransactions

Find matching transactions within a block

{
  block: <Hex Encoded Raw Block String>
  outputs: [<Output Script Hex String>]
}

@throws
<Error>

@returns
{
  outputs: [{
    script: <Output Script Hex String>
    tokens: <Output Value Number>
    transaction_id: <Transaction Id Hex String>
    transaction_vout: <Transaction Output Index Number>
  }]
}

scriptAsScriptElements

Map a serialized script into an array of script elements

{
  script: <Script Hex String>
}

@throws
<Error>

@returns
{
  [elements]: [<Data Buffer>, <Script OP_CODE Number>]
}

scriptElementsAsScript

Map array of script buffer elements to a fully formed script

{
  elements: [<Data Buffer>, <Script OP_CODE Number>]
}

@throws
<Error>

@returns
{
  script: <Script Hex String>
}

unsignedTxFromPsbt

Get the unsigned transaction out of a PSBT

{
  psbt: <PSBT Hex String>
}

@throws
<Error>

@returns
{
  transaction: <Unsigned Transaction Buffer Object>
}