[Waiting] mod: Lit protocol token gated casts by davidfurlong · Pull Request #92 · mod-protocol/mod · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
29 changes: 28 additions & 1 deletion docs/pages/create-mini-app/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,38 @@ export type ModElement =
elements?: string | ElementOrConditionalFlow[];
onload?: ModEvent;
}
| {
ref?: string;
type: "select";
options: Array<{ label: string; value: any }>;
placeholder?: string;
isClearable?: boolean;
onchange?: ModEvent;
onsubmit?: ModEvent;
}
| {
type: "combobox";
ref?: string;
isClearable?: boolean;
placeholder?: string;
optionsRef?: string;
valueRef?: string;
onload?: ModEvent;
onpick?: ModEvent;
onchange?: ModEvent;
}
| {
ref?: string;
type: "textarea";
placeholder?: string;
onchange?: ModEvent;
onsubmit?: ModEvent;
}
| {
ref?: string;
type: "input";
placeholder?: string;
clearable?: boolean;
isClearable?: boolean;
onchange?: ModEvent;
onsubmit?: ModEvent;
}
Expand Down
85 changes: 77 additions & 8 deletions docs/pages/metadata-cache.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The metadata cache can be used to retrieve Open Graph metadata for embeds in cas

It makes use of the [Metadata Indexer](https://github.com/mod-protocol/mod/tree/main/examples/metadata-indexer), an open source and self-hostable service that indexes casts, embeds, and their metadata.

## Usage
We are hosting a free instance of the Metadata indexer that can be reached at https://api.modprotocol.org/api/cast-embeds-metadata

## `/api/cast-embeds-metadata`

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.

Expand Down Expand Up @@ -58,8 +60,8 @@ This will return a JSON object with the following structure:
"metadata": {
"title": "Example Title",
"description": "Example Description",
"image": {
url: "https://example.com/image.png"
"image": {
"url": "https://example.com/image.png"
}
// ...
}
Expand All @@ -73,8 +75,75 @@ Returned metadata objects conform to the `UrlMetadata` type. This can then be us
```typescript
import { UrlMetadata } from "@mod-protocol/core";

cast.embeds.map((embed, index) => {
const embedData: UrlMetadata = metadataResponse[cast.hash][index]
return <RenderEmbed embed={embedData} />
})
```
cast.embeds.map((embed) => {
const metadata: UrlMetadata = metadataResponse[cast.hash][embed.url];
return <RenderEmbed metadata={metadata} />;
});
```

## `/api/cast-embeds-metadata/by-url`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider renaming these endpoints. I suggest /embed-metadata/by-casts and /embed-metadata/by-urls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but that means no backwards compat; will have to let integrators know

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, but that means no backwards compat; will have to let integrators know


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

<Tabs items={["Shell", "JS (fetch)", "Node.js v18+ (fetch)"]}>
<Tabs.Tab>
```bash
curl --request POST \
--url https://api.modprotocol.org/api/cast-embeds-metadata/by-url \
--header 'Content-Type: application/json' \
--data '["https://google.com","https://twitter.com"]'
```
</Tabs.Tab>
<Tabs.Tab>
```js
const request = await fetch("https://api.modprotocol.org/api/cast-embeds-metadata/by-url", {
body: JSON.stringify(["https://google.com","https://twitter.com"]),
method: 'POST',
headers: {
'Content-Type': "application/json"
}
});
const metadata = await request.json();
```
</Tabs.Tab>
<Tabs.Tab>
```js
const request = await fetch("https://api.modprotocol.org/api/cast-embeds-metadata/by-url", {
body: JSON.stringify(["https://google.com","https://twitter.com"]),
method: 'POST',
headers: {
'Content-Type': "application/json"
}
});
const metadata = await request.json();
```
</Tabs.Tab>
</Tabs>

This will return a JSON object with the following structure:

```json
{
"https://google.com": {
"title": "Example Title",
"description": "Example Description",
"image": "https://example.com/image.png"
// ...
},
"https://twitter.com": {
"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.

```typescript
import { UrlMetadata } from "@mod-protocol/core";

const metadata: UrlMetadata = metadataResponse[embed.url];
return <RenderEmbed metadata={metadata} />;
```
7 changes: 6 additions & 1 deletion examples/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ MICROLINK_API_KEY="REQUIRED"
OPENSEA_API_KEY="REQUIRED"
CHATGPT_API_SECRET="REQUIRED"
NEYNAR_API_SECRET="REQUIRED"
LIVEPEER_API_SECRET="REQUIRED"
LIVEPEER_API_SECRET="REQUIRED"
DATABASE_URL="REQUIRED"
# Must be funded with MATIC on Mumbai for Irys https://mumbaifaucet.com/
PRIVATE_KEY="REQUIRED"
GATEWAY_URL="REQUIRED"
SIMPLEHASH_API_KEY="REQUIRED"
6 changes: 5 additions & 1 deletion examples/api/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
reactStrictMode: true,
transpilePackages: ["@mod-protocol/react"],
transpilePackages: [
"@mod-protocol/react",
// Fixes https://discord.com/channels/896185694857343026/1174716239508156496
"@lit-protocol/bls-sdk",
],
};
12 changes: 10 additions & 2 deletions examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@
"lint": "next lint"
},
"dependencies": {
"@irys/sdk": "^0.0.4",
"@lit-protocol/lit-node-client": "^3.0.24",
"@lit-protocol/types": "^2.2.61",
"@mod-protocol/core": "^0.0.2",
"@reservoir0x/reservoir-sdk": "^1.8.4",
"@vercel/postgres-kysely": "^0.6.0",
"bip39": "^3.1.0",
"chatgpt": "^5.2.5",
"cheerio": "^1.0.0-rc.12",
"ethers": "^5.6.9",
"kysely": "^0.26.3",
"next": "^13.5.6",
"open-graph-scraper": "^6.3.2",
"pg": "^8.11.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"siwe": "^1.1.6",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@types/node": "^17.0.12",
Expand All @@ -35,4 +43,4 @@
"tsconfig": "*",
"typescript": "^5.2.2"
}
}
}
130 changes: 130 additions & 0 deletions examples/api/src/app/api/cast-embeds-metadata/by-url/route.ts
Loading