How to get the return value of IPFS infura?

Hi to all,

Sorry if my question is very elementary and simple. Consider the following function:

function ipfsStore(){
    const IPFS = require('ipfs-mini');`
    const ipfs = new IPFS({ host: '', port: 5001, protocol: 'https' });

    ipfs.addJSON({ somevalue: 2, name: 'Nick' }, (err, result) => {
    if (err){

How can I “return” the “result” value form this function? Where should I put the “return result” sentence to get the right value ( I mean IPFS hash value)?

Thanks in advance

You can’t really return the result. You are within a callback function, this means you would pass on the result into another function instead of returning it.

Your problem is not really related to IPFS, it’s a JavaScript question. So finding out how asynchronous programming with callbacks in JavaScript work should get you started.


AddJSON seems return CID (or hash of your json) so if you need to return hash yep. after vmx have reason here you cannot return result you run a callback.

somes approach exist for that :

  • use promise + await / asunc
  • use promise + global variable
  • use callback