Retrieve files from ipfs in ethereum

Hi, I’m using IPFS to store some data and is storing the generated hash on to a smart contract(ethereum). But when I try to retrieve the data I’m getting a error:

ipfs fetch error Error: Non-base58 character

I used ipfs get to retrieve the data

ipfs.files.get(hash, [callback])

Is there any other way to retrieve it?

We’re going to need some more information. What’s the hash you’re trying to use?

I’m trying to both save and retrieve the hash generated by the IPFS on to a ethereum contract.
For example “QmPHuBTZUywQxajJWJhP2FFECYYkhNH3U4zfaxCzhVvks9”
When I try to save it, it returns

Uncaught (in promise) Error: invalid address

I tried saving it in bytes also, but no use.
And when I try to retrieve an already saved hash from IPFS using the ipfs.files.get() I’m getting a non-base58 character error

ipfs.files.get(fileHash, function (err, res){ // fileHash contains the ipfs generated hash
if(err || !res) return console.error(“ipfs fetch error”, err, res);
console.log(res);
});

Is that the exact path you’re using? ipfs.files.get("QmPHuBTZUywQxajJWJhP2FFECYYkhNH3U4zfaxCzhVvks9", function (err, res) {...}) should work.

Would it be possible to post a minimum code example somewhere (something I could just load in my browser to see the error)?

You may also want to take a look at the following example, it may help you figure out what’s going wrong:

If it helps, these are the error which I’m getting on the console

Uncaught (in promise) Error: invalid address
at inputAddressFormatter (“http://localhost:8081/app.js:6532:11”)
at inputTransactionFormatter (“http://localhost:8081/app.js:6358:20”)
at “http://localhost:8081/app.js:9831:28
at Array.map (native)
at Method.formatInput (“http://localhost:8081/app.js:9830:32”)
at Method.toPayload (“http://localhost:8081/app.js:9856:23”)
at Eth.send [as sendTransaction] (“http://localhost:8081/app.js:9881:30”)
at SolidityFunction.sendTransaction (“http://localhost:8081/app.js:84803:15”)
at SolidityFunction.execute (“http://localhost:8081/app.js:84886:37”)
at “http://localhost:8081/app.js:82906:16

Oh. That’s an error from Ethereum, not IPFS. Unfortunately, that isn’t nearly enough information to actually debug this.

  1. What do you mean by “trying to save in an ethereum contract”.
  2. What’s the address you’re trying to read from IPFS.

Honestly, without some code this will be pretty hard to debug.

I’m using this code(in my js file) to retrieve the data back from ipfs (where genHash is the hash being generated by IPFS).

ipfs.files.get(genHash, function (err, res){
if(err || !res) return console.error(“ipfs fetch error”, err, res);
console.log(res);
});

Adding data to ipfs is working using the below code:

var files = {
weight: 5,
no_of_cuts: 2
}
var files_json = JSON.stringify(files);
ipfs.files.add(new Buffer(files_json), function (err, res){
if(err || !res) return console.error(“ipfs add error”, err, res);
var genHash = res[0].hash;
});

But when I try to pass the generated hash (genHash) to save it in my contract, it returns with all the above errors.
I’m calling my contract from js file using the below code:

GemCreation.deployed().then(function(instance) {
instance.dataSubmission(id ,genHash,{from: account, gas: 3000000, value: web3.toWei(1, ‘ether’)})
.then(function(v){
console.log(‘successfully added’);
});
});

and my contract code is :

function dataSubmission(uint id, bytes gHash) payable returns (bool result) {
detailsHashTable[id].hash = gHash;
return true;
}

// mapping is done as below

struct detailsHash{
bytes hash;
}

mapping(uint=>detailsHash) public detailsHashTable;