我嘗試了許多不同的想法,但無法找到如何通過 HTTP 請求獲取 NFT 的影像。我試圖找到一個回傳令牌 URI 的 HTTP API,但找不到任何東西。沒有令牌 URI,我無法在 ipfs 上找到影像。
uj5u.com熱心網友回復:
如果獲取到 NFT 的“tokenUri”并粘貼到瀏覽器
ipfs://tokenUriHERE
您將看到像這樣的 json 格式的 NFT 元資料。
{
"name": "name it",
"image": "ipfs://QmR36VFfo1hH2RAwVs4zVJ5btkopGip5cW7ydY4jUQBrKW",
"description": "description",
"attributes": [
{
"trait_type": "Artist",
"value": "value"
},
] }
如果您獲得影像 URL 并將其粘貼到瀏覽器,您將看到該影像。
如果您想撰寫代碼來獲取資料,只需發送 get 請求以 ipfs://tokenUriHERE獲取 JSON,檢索影像然后獲取影像。
或者您可以使用庫。在 javascript 中,web3.storage
import { Web3Storage } from 'web3.storage'
const token = process.env.API_TOKEN
const client = new Web3Storage({ token })
async function retrieveFiles () {
const cid =
'bafybeidd2gyhagleh47qeg77xqndy2qy3yzn4vkxmk775bg2t5lpuy7pcu'
// You can fetch data using any CID, even from IPFS Nodes or Gateway URLs!
const res = await client.get(cid)
const files = await res.files()
for (const file of files) {
console.log(`${file.cid}: ${file.name} (${file.size} bytes)`)
}
}
retrieveFiles()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/415112.html
標籤:
上一篇:一個url但對失敗的不同回應
下一篇:從教程中執行apk時API不起作用。“錯誤代碼”:“steps.oauth.v2.FailedToResolveAPIKey”
