我使用nft.storage将数据存储在ipfs上,使用storeBlob存储数据,因为我只想存储数据。
index.js:13
Uncaught (in promise) TypeError: source is not async iterable
at last (index.js:13:1)
at pack (index.js:14:1)
at packCar (lib.js:757:1)
at NFTStorage.encodeBlob (lib.js:472:1)
at NFTStorage.storeBlob (lib.js:151:1)
at NFTStorage.storeBlob (lib.js:542:1)
at storeAsset (Results.jsx:36:1)
at encryptingData (Results.jsx:63:1)我用这个函数来弄清楚。
这里我的元数据是加密的字符串。
const client = new NFTStorage({ token: NFT_STORAGE_KEY })
async function storeAsset(metadata) {
const cid = await client.storeBlob(metadata);
console.log("Metadata stored on Filecoin and IPFS with cid:", cid)
}发布于 2022-11-20 09:43:11
你能试着换下一行吗?
在此之前:
const cid = await client.storeBlob(metadata);之后:
const cid = await client.storeBlob(new Blob([metadata]));发布于 2022-11-20 09:55:03
client.storeBlob可能正在等待一个流。但是,如果您真正需要的是异步迭代,那么您可能可以通过这样的方法来解决:
async function* makeAsyncIterable(metadata) {
yield metadata;
}
const metadata = "???";
const metadataAsyncIterable = makeAsyncIterable(metadata);
console.log(Symbol.asyncIterator in metadataAsyncIterable); // Output: true发布于 2022-11-20 17:43:03
还不清楚metadata变量是什么。这就是您应该如何实现client.storeBlob
await client.storeBlob(
new Blob([
{
chain:"goerli",
contract_address: "0x....",
transaction_hash: "0x....",
description:"description",
address:"0x.....",
},
])
);https://stackoverflow.com/questions/74506692
复制相似问题