0

我正在尝试使用ipfs-http-client包将小 JSON 添加到 IPFS,我可以看到 IPFS 在本地机器中作为守护进程运行而没有任何问题,而且我还可以通过 linux 控制台向 IPFS 添加字符串但是当我从 react 应用程序尝试相同的事情时它是不工作

const ipfsClient = require('ipfs-http-client')
    

    // i have tried below two ways to create ipfs object both are returning 
    // object so no issues
    
    const ipfs =  ipfsClient.create ({
       host: 'localhost',
        port: 5001,
        rotocol: 'http'
    })

    const ipfs = ipfsClient.create('/ip4/0.0.0.0/tcp/5001');

    // Problem is i am unable to add the file to ipfs with below call
    // because it hangs forever


    obj[address] = {
        fullname,
        status: "Active"
    }
    
            let buffer = Buffer.from(JSON.stringify(obj));
            console.log(buffer);
            console.log(ipfs);
            return new Promise((resolve, reject) => {
                ipfs.add(buffer, async (error, response) => {
                    if (error) {
                        console.error(error);
                    } else {
                        const hash = await response[0].hash;
                        resolve(hash);
                    }
                })
            })
4

0 回答 0