Using js-ipfs in a `create-react-app`
Explore the docs
·
View Demo
·
Report Bug
·
Request Feature/Example
- Table of Contents
- About The Project
- Getting Started
- Usage
- References
- Documentation
- Contributing
- Want to hack on IPFS?
- Read the docs
- Look into other examples to learn how to spawn an IPFS node in Node.js and in the Browser
- Consult the Core API docs to see what you can do with an IPFS node
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
- Check out https://docs.ipfs.io for tips, how-tos and more
- See https://blog.ipfs.io for news and more
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- Node.js - Download & Install Node.js and the npm package manager.
> npm install
> npm start
Now open your browser at http://localhost:3000
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed! Read how to host a single page or an entire website on IPFS.
But with modern hosting services like Heroku, Netlity or Fleek, you can skip the build because they will do a complete github deployment for you. See the React official page about deployment for more information.
This is a minimal demonstration of how to use js-ipfs
in a create-react-app
generated app.
It boots up a js-ipfs
instance (an IPFS node) via a custom React hook in ./src/hooks/use-ipfs-factory.js
, which is called from ./src/App.js
. Once the IPFS node is set up, ./src/App.js
displays the PeerId of this node and the version number of js-ipfs
used to spawn it.
All React applications store their main logic in App.js
:
App.js
renders the cosmetics of the demo and callsuseIpfs
to retrieve theid
of the nodeuseIpfsFactory.js
initialises and closes the IPFS local nodeuseIpfs.js
does the actual calls to IPFS to retrieve the property specified in argument (here the retrieved property isid
, requested fromApp.js
)
Once the IPFS node is set up, App.js
displays its ident and its version number.
Side note: The PeerId of the IPFS node is the multihash of the public key of this node. The public-private key pair of a node is generated by typing
ipfs init
.
Note: this example is useful to learn how to spawn IPFS from a web page. It is also possible to spawn an IPFS daemon from the command line with ipfs daemon
. While self-hosting is advised, one can also delegate IPFS operations to a third-party like Infura. See tutorials here and here.
For more examples, please refer to the Documentation
- Documentation:
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the IPFS Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -a -m 'feat: add some amazing feature'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:
Read the Code of Conduct and JavaScript Contributing Guidelines.
- Check out existing issues The issue list has many that are marked as 'help wanted' or 'difficulty:easy' which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
- Look at the IPFS Roadmap This are the high priority items being worked on right now
- Perform code reviews More eyes will help a. speed the project along b. ensure quality, and c. reduce possible future bugs.
- Add tests. There can never be enough tests.
- Join the Weekly Core Implementations Call it's where everyone discusses what's going on with IPFS and what's next