Search code examples
ipfs

ipfs.add() returns Object [AsyncGenerator] {}


I am unable to figure out what mistake i have done in the code

Whenever i am calling api, ipfs.add('hello') returns [object AsyncGenerator]

https://gateway.ipfs.io/ipfs/[object AsyncGenerator]

  const addFile = async () => {
            const Added = await ipfs.add('hello');
            return Added;
        }
        const fileHash = await addFile();
        return fileHash;

Solution

  • You can iterate over the result of .add() like so:

    for await (const item of Added) {
      console.log('item', item)
    } 
    

    item { path: 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX',
    cid: CID(QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX), size: 13 }