Metadata Cache

Metadata Cache

The metadata cache can be used to retrieve Open Graph metadata for embeds in casts, useful for rendering embeds in a cast without having to make a request to each embed URL.

It makes use of the Metadata Indexer (opens in a new tab), an open source and self-hostable service that indexes casts, embeds, and their metadata.

Usage

Fetching metadata from the cache is as simple as making a POST request to the following endpoint with a list of cast hashes in the body.

curl --request POST \
--url https://api.modprotocol.org/api/cast-embeds-metadata \
--header 'Content-Type: application/json' \
--data '["0x15f0c75fd1735789b52c708f858816d149910c1d","0x1af019b5ad82f159efa3f2c51b4d4653604180d4"]'

This will return a JSON object with the following structure:

{
  "0x1234...abcd": [
    {
      "castHash": "0x1234...abcd",
      "url": "...",
      "normalizedUrl": "...",
      "index": 0,
      "urlMetadata": {
        "title": "Example Title",
        "description": "Example Description",
        "image": "https://example.com/image.png"
        // ...
      }
    }
  ]
}

Returned metadata objects conform to the UrlMetadata type. This can then be used to render embeds in a cast.

import { UrlMetadata } from "@mod-protocol/core";
 
cast.embeds.map(embed => {
  const metadata: UrlMetadata = metadataResponse[cast.hash][embed.url]
  return <RenderEmbed metadata={metadata} />
})