So I created a truffle folder for solidity, wrote down the basic test.js and ipfsContract.sol needed (Creating a form in IPFS for users to enter data). HOWEVER, on doing truffle test I get 0 passing in green, although I do ask test.js to print out the hash code!

[I also do one edit in test.js - const IPFS = require('ipfs') // importing IPFS module and instantiating it. const node = new IPFS()]

Reading various articles on the net, I am thinking if I need to create an extra .js file outside the truffle directory to make it work. But I could be wrong! ANy help?


1 Answer 1


I have used Js implementation for IPFS

Refer this :- https://github.com/ipfs/js-ipfs-api

Connect IPFS as follows :-

   var ipfsAPI = require('ipfs-api')

   // connect to ipfs daemon API server
   var ipfs = ipfsAPI('localhost', '5001', {protocol: 'http'})

I have given a code for adding a textinput into ipfs for your reference. The given code will convert the input to hash and passed it into the contract function.


     ipfs.add(new Buffer(amount), function (err, res){
           if(err || !res) return console.error("ipfs add error", err, res);

              res.forEach(function(text) {
                    console.log('successfully stored', text.hash);
                    //Storing hash in blockchain                   
                               SimpleStorage.deployed().then(function(instance) {
                                  console.log("Initializing set function");
                                  instance.set(text.hash,{from: account, gas: 3000000})
                                           console.log("Function  set Executed");


                            }).catch(function(e) {

  • Right thanks! But did yu write all this in test.js provided by truffle? Commented Mar 9, 2018 at 10:11
  • @RahulKothari I didn't get. Commented Mar 9, 2018 at 10:37
  • I mean, can it be written in test.js (that comes in the test folder when we do truffle init) ALSO, why do we have amount in the first line? Commented Mar 9, 2018 at 13:52
  • Test.js deals with testing of solidity.you have to add the above code in app.js to convert your input into hash.amount is the input from frontend,which is used for creating hash. Commented Mar 9, 2018 at 14:22
  • Perfect! Thank you so much! Lastly, why do you mention amount in the first line? Commented Mar 10, 2018 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.