Interacting With Ordinals Nft’s Via An Http API

Interacting With Ordinals Nft’s Via An Http API


Meta Description: OrdAPI is a prime example of how the latest development tools have made the process much easier. This article delveS into the process of building a basic web application using OrdAPI.

Have you been following the latest trends in Ordinals? If yes, then you must have noticed that a larger percentage of your interactions with ordinals have been through the ord CLI tool.

No doubt the ord CLI tool offers great features and functionality. But there's no denying it's not been easy to develop web applications on the tool. Fortunately, the latest tools available have made development easier and a good example is OrdAPI.

This article explores how to build a simple web application using OrdAPI.

Use Case of the API

You can view the API documentation on the OrdAPI homepage. Reading through, it's hard to deny that it is quite intuitive and simple.

A good demonstration of the OrdAPI is generating a recent inscription feed. To do that, all API outputs will be in JSON format.

GET https://ordapi.xyz/feed

This will fetch a JSON output:
{
   "rss": {
       "@version": "2.0",                                                                                                             "channel": {
            "description": null,
            "generator": "ord",
            "item": [
              {
                 "guid":                             "/inscription/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0",
"link": "https://ordinals.com/inscription/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0",
"title": "Inscription 52916"
},
{
"guid": "/inscription/69c20eaa58d0bfd804a962ce95a895afe974210ae0dffa9eb16e033369fca0a5i0",
"link": "https://ordinals.com/inscription/69c20eaa58d0bfd804a962ce95a895afe974210ae0dffa9eb16e033369fca0a5i0",
"title": "Inscription 52915"
},
...
]
}
}
}

Considering the output is saved as inscriptions. One can access the inscriptions like:

inscriptions["rss"]["channel"]["item"] // -> array of insriptions

var singleInscription = inscriptions["rss"]["channel"]["item"][0] // -> object of first inscription

With easy access to the inscriptions, fetching their images using the /inscriptions/:inscription_id endpoint becomes straightforward. Here'a how to fetch the first one:

GET https://ordapi.xyz/inscription/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0

This will fetch:
{
"address": "bc1p6mygc82l08jxres7xdv0836jl570w6j9gt5v3uelryw206kdyh3svnm2gn",
"content": "/content/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0",
"content length": "4205 bytes",
"content type": "image/png",
"genesis fee": "8344",
"genesis height": "/block/775984",
"genesis transaction": "/tx/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4",
"id": "7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0",
"location": "7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4:0:0",
"offset": "0",
"output": "/output/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4:0",
"output value": "10000",
"preview": "/preview/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0",
"sat": "/sat/1926178024163094",
"timestamp": "2023-02-11 05:59:44 UTC"
}

This code features the entire inscription metadata. The “preview” and “content” keys in the code will facilitate easy access to the image:

GET https://ordapi.xyz/preview/7aa65adc99537fd5237d705c30bcdbcd7d9ab2e28747670caee0fb74410bfdc4i0

Which would fetch:

Check our guide of the most promising crypto

Read more