Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE

How to Get Ordinals Inscription Data With Ordhook

Discover how to retrieve ordinals inscription data with Ordhook, a reliable index for ordinals.

Type
Tutorial
Topic(s)
Bitcoin
Published
November 2, 2023
Author(s)
Developer Advocate
Ordhook, an indexer for Bitcoin
Contents

We announced Ordhook in September, a client indexer for ordinals data. Reliable indexers are particularly important for metaprotocols like ordinals where standards, such as what counts as an inscription and what does not, are changing seemingly every day.

Ordhook is a powerful tool that gives developers an easier way to access raw ordinals inscription data and customize what information they want to consume—in order to iterate, splice, dice and build. In fact, Ordhook powers all of Hiro’s ordinals tooling, including our Ordinals Explorer and Ordinals API.

Since you can customize what data you ingest, ordinals offers a nimble solution to power your app while also being reliable: ordhook is reorg-aware and will automatically roll back any invalid transactions in your database in the event of a fork or reorg.

Ordhook is a powerful tool that gives you an easier way to access raw ordinals inscription data and customize what information you want to consume.

In this blog, we’ll walk through a brief tutorial showing you how to explore BRC-20 inscription data with Ordhook. First, you’ll learn how to deliver data payloads to an observer, and then we’ll cover how to create custom views of ordinals data with JavaScript. This GitHub repo gives you all of the instructions you need to follow along. 

If you’re a visual learner, watch a recording of our recent webinar, where we walk through some of these steps, beginning at 12:50:

Set Up Ordhook

Before you begin, you’ll need to set up Ordhook. This involves two main steps:

  • Set up a Bitcoin node: Ordinals are built on Bitcoin, and you’ll need to run a node in order for Ordhook to pull new inscription data from the Bitcoin blockchain. For more detailed instructions, start here.
  • Connect Ordhook to your Bitcoin node: This will allow the Ordhook indexer to index (sorry) the data from your Bitcoin node and push that data to a database that is application-friendly.

Once the Bitcoin node and Ordhook index are synced, the fun can begin. There are two main commands you can use:

  • <code-rich-text>scan<code-rich-text> allows you to scan any section of the blockchain by block height to then return a given type of information, in this case, BRC-20 inscription data. 
  • <code-rich-text>service<code-rich-text> allows you to run ordhook as a service for running an ongoing observer.

Ordhook Scan

Now that Ordhook is configured, and your Bitcoin node is set up, try out the following Ordhook command: 


ordhook scan blocks 784726 784727

Ordhook will return any inscription data it finds between whichever two blocks you indicate. In this instance, the block height above corresponds to the first two inscriptions ever made. 

Once you’ve run the <code-rich-text>scan<code-rich-text> command, you can inspect the data manually in your terminal, or deliver the payload to an API or to any observer. To do the latter, you will use the HTTP post method.

Ordhook will return any inscription data it finds between whichever two blocks you indicate.

If you want to go beyond visually inspecting the data, and work more programmatically with this data, you might want to deliver these payloads to an API. For example, in theory, you could have a web server that runs a simple JavaScript file that takes requests delivered to this end point and then returns a raw JSON. Or you could get much more elaborate and create entire applications, such as a notification system using Twilio and Zapier to deliver text messages when your favorite inscription or collection is bought or sold. The sky’s the limit!

Ordhook Service

One of the powerful things you can do with Ordhook is quick iterative development if you’re interested in building metaprotocols with ordinals. Ordhook is powerful enough to enable custom views of raw blockchain data, whether you want to index particular blocks or particular subsets of inscriptions.

Let’s look at a specific example. Run the following Ordhook command:


ordhook service start

With this command, you can push an entire block’s raw data to the display in your web server. However, there’s a lot of information to parse, and you might only want specific types of data, say only data related to BRC-20 tokens.

To do that, you can refine the data Ordhook fetches for you, using a little bit of logic and JavaScript skills. That logic can present the data in a human readable format or pull specific metadata that you need for your app.

From there, you can use this refined data to build your own database (and then build your own custom API or service around it).

Ordinals API vs Ordhook

We also offer the Ordinals API, which is another way for you to pull inscription data into your app. But when should you use Ordhook versus the Ordinals API? We thought you’d never ask.

When to Use the Ordinals API

The Ordinals API delivers reliable data payloads to web applications and can handle high volumes of traffic. Leveraging an API is great for devs who value performance and low latency. In turn, you hand off data maintenance and indexing to a 3rd party, such as Hiro, to deliver that at scale for you.

View our Ordinals API docs here.

When to Use Ordhook

If you’re a fairly advanced developer, Ordhook gives you more power to customize how you pull and work with blockchain data. You might want to create your own index for a specific metaprotocol (e.g. BRC-20 or Bitmap).

An indexer is helpful if you want custom or finely tailored slices of blockchain data to work with (such as a unique subset of inscriptions). It’s also great if you want to be fully sovereign and not rely on any 3rd party for some hosted service. However, using an indexer yourself also has challenges: it won’t be easy to deliver data to a lot of users through a web app or to maintain constant uptime under high traffic scenarios.

View Ordhook docs here.

Conclusion

With Ordhook, your only limit to build is your power to create JavaScript logic to parse inscription data however you need. Then you can create custom views of your own data to support iterative development.

Now that you’ve learned some of the basics of building with Ordhook, dive into its full potential in our docs.

Product updates & dev resources straight to your inbox
Your Email is in an invalid format
Checkbox is required.
Thanks for
subscribing.
Oops! Something went wrong while submitting the form.
View docs
Copy link
Mailbox
Hiro news & product updates straight to your inbox
Only relevant communications. We promise we won’t spam.

Related stories