【发布时间】:2022-11-12 00:04:06
【问题描述】:
我正在使用 ipfs-http-client 模块与 IPFS 进行交互。我的问题是我需要我生成的链接上的文件扩展名,而且似乎我只能使用wrapWithDirectory 标志(-w 使用命令行)来获取它。但是到目前为止,此标志使结果为空。 IPFS 上的文档只是关于命令行的,我只找到了一些关于如何做到这一点的教程,但是使用 JS 以外的其他工具,或者手动上传文件夹。我需要从一个 JS 脚本,从一个文件中完成。动机是我想为 NFT 生成元数据,并且元数据字段需要指向具有特定扩展名的文件。
完整细节:我需要在 Opensea 上添加一个 GLB 文件。 GLB 就像 GLTF,它是 3D 文件的标准。 Opensea 可以检测 NFT 元数据的animation_url 字段并渲染该文件。但它需要以.glb 结尾。翻译一下,我的 NFT 需要它的元数据看起来像这样:
{
name: <name>,
description: <description>,
image: <image>,
animation_url: 'https://ipfs.io/ipfs/<hash>.glb' // Opensea requires the '.glb' ending.
}
到目前为止,我这样做的方式如下:
import { create } from 'ipfs-http-client';
const client = create({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
headers: { authorization },
});
const result = await client.add(file); // {path: '<hash>', cid: CID}
const link = `https://ipfs.io/ipfs/${result.path}` // I can't add an extension here.
在该代码中,我可以将 animation_url: link 放入元数据对象中,但 OpenSea 无法识别它。
我也尝试过添加上面提到的选项:
const result = await client.add(file, {wrapWithDirectory: true}); // {path: '', cid: CID}
但是result.path 是一个空字符串。
如何生成以.glb 结尾的链接?
【问题讨论】:
标签: ipfs nft opensea js-ipfs ipfs-http-client