Data Storage
Mods may need to store data beyond what fits in a Farcaster cast, or in a different structure.
One pattern Mods can use to solve this problem is by utilizing the Open graph protocol (opens in a new tab), JSON schema (opens in a new tab) web standards, in combination with any third party storage.
An example of how storage works for the Poll
Mod
- The Poll Creation Mod wants to store poll metadata, such as when the poll ends, the question, and the choices.
- The Poll Creation Mod collects the information via a form, and POSTs it to the backend
- The Backend generates an image from the text, to use as an open graph image, which serves as a fallback image interface for the Mod, and uploads it somewhere to get a url (for example imgur)
- The Backend constructs a
JSON schema
object using a well-known schema definition, or a schema definition defined by any Mod. This object includes the poll metadata, and image to use for the open graph. In this case, the Poll Mod defines aPoll
Definition in it's Manifest that is used. - The Backend stores this
JSON schema
JSON object in some sort of storage (our Mod uses arweave for this), and gets in return a unique URL or identitifer for it. - The Backend constructs a URL that starts with a proxy gateway (we're using our own, https://cast.fun/mods/ (opens in a new tab)) with the path to the stored JSON in it.
This proxy gateway is responsible for fetching and serving these
JSON schema
objects as JSON Linked-data (opens in a new tab), serving other web metadata like open graph data and images, and can optionally serve a fallback Mod interface. - This url is returned to the client, and added to the Farcaster cast as an embed, or shared elsewhere.
- The Render-poll Mod is rendered by apps that have integrated it when a URL has metadata with
JSON schema
with the unique identifier of thePoll
Model defined by thePoll
Mod - The Render-poll Mod, when rendered, shows a voting interface using the
Poll
metadata, stores votes asreply casts
by the user, and uses a backend to fetch all casts responding to this url that match a vote format.
Benefits of this design
- It works with existing open graph previews on the web, without a need for new integrations
- It uses widely adopted web standards -
JSON schema
is used by search engines like google to enrich search results with things like Jobs. - The degree of decentralization, as well as the choice of storage is flexible and unopionated.
- It supports flexible data schemas and models that can be arbitrarily large
- Gateways that choose to use this URL pattern can be rewritten by apps, bypassed and all the data needed to retrieve the metadata is in the shared url itself
- JSON is a dev friendly format
JSON Schema
allows for the composition of Models
Why not use open graph?
Open graph is good for strings, but doesn't natively support JSON (although you could serialize JSON as a set of key value string pairs). Open graph doesn't have a standard for the definition of data models.
Practical tips
- og title: 64 characters or less recommended (web standards)
- og images: recommend a 1200x600 and leave at least 10% pixel padding around the image where there shouldn't be any text, or it's at risk of being cropped
- og descriptions: up to 176 characters on desktop are shown in apps like Warpcast, no characters shown on mobile