【问题标题】:Can we store a string like "Hello world" on ipfs using web3storage or nft.storage我们可以使用 web3storage 或 nft.storage 在 ipfs 上存储像“Hello world”这样的字符串吗
【发布时间】:2022-11-24 02:02:12
【问题描述】:

我正在尝试将我的加密字符串存储在 nft.storage 上,但出现错误,

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:41:1)
    at encryptingData (Results.jsx:71:1)

我试过的是

const metadata = JSON.stringify(encryptedString);
storeAsset(metadata);

async function storeAsset(metadata) {
    
    const cid= await client.storeBlob(new Blob([metadata]));
    console.log(cid);
 }

【问题讨论】:

    标签: json blockchain metadata ipfs nft


    【解决方案1】:
    import { Web3Storage } from "web3.storage"; 
    
    const token = process.env.NEXT_PUBLIC_TOKEN; 
      
     function makeStorageClient() { 
       return new Web3Storage({ token }); 
     } 
      
     function makeFileObjects(text) { 
       const obj = { email: text }; 
       const blob = new Blob([JSON.stringify(obj)], { type: "application/json" }); 
       const files = [new File([blob], "email.json")]; 
       return files; 
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 2016-04-05
      • 2017-07-29
      • 2012-05-10
      • 2012-02-23
      • 1970-01-01
      • 2019-09-19
      相关资源
      最近更新 更多