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

ordpool-parser

v0.0.10-beta.4

Published

The parsing engine that detects Inscriptions, SRC-20 Stamps, CAT-21 Ordinals, and Runes in Bitcoin transactions.

Downloads

1,209

Readme

ordpool-parser

The parsing engine that detects Inscriptions, SRC-20 Stamps, CAT-21 Ordinals, and Runes in Bitcoin transactions. The compiled code has zero dependencies and works in the Browser and in Node.js out of the box.

The latest version of this script is used by https://ordpool.space

🚀 Usage

This package has zero dependencies and should "just work". First, install it:

npm install ordpool-parser

Then, you can use the parser in your project. It expects a transaction in JSON format from an Esplora API. (This format is different from the JSON returned by a Bitcoin Node RPC.)

To avoid confusion, here are the different kinds of "Electrum" servers explained:

  • Electrum and ElectrumX are basic indexers for Bitcoin
  • romanz/electrs (Electrum Server in Rust) is re-implementation Electrum
  • "Esplora - Electrs backend API" is a fork by blockstream.info with a powerful REST API

Esplora is the backend mempool.space uses, and is also what powers blockstream.info! The ordpool-parser was only tested with this API.

import axios from 'axios';
import { InscriptionParserService } from 'ordpool-parser';

async function getInscriptions(txId: string) {

  const response = await axios.get(`https://mempool.space/api/tx/${txId}`);
  // OR 
  // const response = await axios.get(`https://blockstream.info/api/tx/${txId}`);
  const transaction = response.data;

  return InscriptionParserService.parse(transaction);
}

const parsedInscriptions = await getInscriptions('f1997166547da9784a3e7419d2b248551565211811d4f5e705b685efa244451f');

if (!parsedInscriptions.length) {
  console.log('No inscriptions found!');
} else {
  // Output: text/html;charset=utf-8
  console.log(parsedInscriptions[0].contentType);

  // UTF-8 encoded string (not intended for binary content like images or videos)
  // Output: <html><!--cubes.haushoppe.art--><body> [...]
  console.log(parsedInscriptions[0].getContent());

  // Base64 encoded data URI that can be displayed in an iframe
  // Output: data:text/html;charset=utf-8;base64,PGh0bWw+PCEtLWN1YmVzLmhhdXNob3BwZS5hcnQtLT48Ym9keT4 [...]
  console.log(parsedInscriptions[0].getDataUri());
}

This example uses axios, a popular HTTP client for both browser and Node.js environments. You can install it via npm install axios. Of course, any other compatible HTTP client will also work.

Note: This is a simplified example! Make sure to handle errors when making HTTP requests, as network issues can occur.

🧡 Contribute

Prerequisites

Node.js (Version 20 or later) to test & compile the TypeScript code to JavaScript.

Install

First, install Node.js version 20. Then, install the NPM dependencies and execute the tests with the following commands:

npm install
npm test

How to add a feature

Every feature must be tested in the browser and in the node environment! Use a mainnet transaction to create a test scenario. The goal of this parser is to parse byte-perfect inscriptions that are identical to ord.

  1. Fetch Transaction Test Data: Save the raw transaction JSON to the testdata folder.

    npm run fetch-tx-testdata

    Enter the transactionId (e.g.78fa9d6e9b2b49fbb9f4838e1792dba7c1ec836f22e3206561e2d52759708251) and check the results.

  2. Fetch Inscription Test Data: Save the reference inscription as a file in the testdata folder.

    npm run fetch-inscription-testdata

    Enter the inscriptionId, which is the transactionId + i + the index (e.g.78fa9d6e9b2b49fbb9f4838e1792dba7c1ec836f22e3206561e2d52759708251i0), and check the results!

  3. Contribute: Add your new feature, include meaningful tests, and submit a pull request if all tests pass.

  4. Hint: Debug the unit tests using VS Code. The launch.json file is already prepared for this purpose.

Build

To build a version without the tests:

npm run build

To publish a new version to NPM:

npm publish