Web3 Blog
Create a web3 blog where your readers can collect blog posts as NFTs
Next.js API Endpoint
Collect Button
Markdown Blog Posts
Last updated
Create a web3 blog where your readers can collect blog posts as NFTs
Last updated
import { UNDERDOG_API_KEY, UNDERDOG_API_URL } from "@/lib/constants"
import { metadataImageUrl } from "@/lib/underdog"
import axios from "axios"
import { NextApiRequest, NextApiResponse } from "next"
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
if (req.method === "GET") {
const response = await axios.get(
`${UNDERDOG_API_URL}/v1/nfts?ownerAddress=${req.query.ownerAddress}&collectionAddress=${req.query.collectionAddress}`,
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${UNDERDOG_API_KEY}`,
},
}
)
res.status(200).json(response.data)
}
if (req.method === "POST") {
const response = await axios.post(
`${UNDERDOG_API_URL}/v1/nfts`,
{
name: req.body.name,
description: req.body.description,
image: metadataImageUrl(req.body.collectionAddress),
collectionAddress: req.body.collectionAddress,
ownerAddress: req.body.ownerAddress,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${UNDERDOG_API_KEY}`,
},
}
)
res.status(200).json(response.data)
}
} catch (e: any) {
console.log(e)
res.status(400).json({ error: e.message })
}
}...
const handleCollect = async () => {
if (publicKey) {
toggleCollecting()
await axios.post("/api/nfts", {
name: entry.title,
description: entry.description,
collectionAddress: entry.collectionAddress,
ownerAddress: publicKey?.toString(),
})
await refreshNfts()
toggleCollecting()
}
}
...export const entry = {
title: "Your Blog Post",
description: "Add a description for your blog post",
collectionAddress: "E6H1MYDiFhUkmAWPnxTMS9iEPpJtvMU6za5pvqUt6Hm3"
}