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;