By now i have developed few basic example apps to execute Ethereum contracts using truffle based web application in a private blockchain.

I have setup an IPFS node in my local. Able to upload files to IPFS and view on the IPFS gateway.

Now Looking for a sample code to connect my IPFS node from my truffle based web app and the perform add/view operations of documents from/to IPFS.

Here is what I am looking for
1. Believe have to install IPFS.js using npm
2. Start the IPFS daemon
3. Connect to my local IPFS Node
4. Modify the html interface to accept a file object
5. Invoke IPFS API to add the file in IPFS and get the hash
6. Store the hash in Ethereum blockchain
7. Change the html interface to accept the file specific hash value
8. Invoke IPFS API to get the file from IPFS based on the provided hash

Help is needed for steps 3, 5 and 8. If you could share a sample code to perform the same will be helpful.

1 Answer 1

  1. Connect to IPFS

const ipfsAPI = require('ipfs-api');
const ipfs = ipfsAPI({ host:'localhost', port: '5001', protocol: 'http' });

  1. Get the file from ipfs by providing the hash value of the file

https://ipfs.io/ipfs/" + hashvalue + "' width=100% />

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.