Store and retrieve files on IPFS (InterPlanetary File System). Use when a user asks to store files in a decentralized way, pin content on IPFS, upload NFT metadata, or use content-addressed storage.
IPFS is a decentralized file storage protocol. Files are content-addressed (identified by hash, not location). Used for NFT metadata, dApp assets, and censorship-resistant content. Pinning services (Pinata, web3.storage) ensure files stay available.
// lib/ipfs.ts — Upload files to IPFS via Pinata
const PINATA_JWT = process.env.PINATA_JWT!
export async function uploadToIPFS(file: Buffer, name: string): Promise<string> {
const formData = new FormData()
formData.append('file', new Blob([file]), name)
formData.append('pinataMetadata', JSON.stringify({ name }))
const res = await fetch('https://api.pinata.cloud/pinning/pinFileToIPFS', {
method: 'POST',
headers: { Authorization: `Bearer ${PINATA_JWT}` },
body: formData,
})
const { IpfsHash } = await res.json()
return `ipfs://${IpfsHash}`
}
export async function uploadJSON(data: object): Promise<string> {
const res = await fetch('https://api.pinata.cloud/pinning/pinJSONToIPFS', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${PINATA_JWT}`,
},
body: JSON.stringify({ pinataContent: data }),
})
const { IpfsHash } = await res.json()
return `ipfs://${IpfsHash}`
}
// Upload NFT image and metadata
const imageHash = await uploadToIPFS(imageBuffer, 'nft-image.png')
const metadata = {
name: 'Cool NFT #1',
description: 'A very cool NFT',
image: imageHash,
attributes: [
{ trait_type: 'Background', value: 'Blue' },
{ trait_type: 'Rarity', value: 'Rare' },
],
}
const metadataHash = await uploadJSON(metadata)
// Use metadataHash as tokenURI in your NFT contract
// Read from IPFS via gateway
const GATEWAY = 'https://gateway.pinata.cloud/ipfs'
async function getFromIPFS(cid: string) {
const res = await fetch(`${GATEWAY}/${cid}`)
return res.json()
}
npx skills add TerminalSkills/ipfs下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer