Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Latest commit

 

History

History
executable file
·
158 lines (112 loc) · 7.9 KB

File metadata and controls

executable file
·
158 lines (112 loc) · 7.9 KB

IPFS in JavaScript logo

IPFS React App

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

Pre requisites

Make sure you have installed all of the following prerequisites on your development machine:

Installation and Running example

> npm install
> npm start

Now open your browser at http://localhost:3000

Available Scripts from create-react-app

In the project directory, you can run:

npm start

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.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

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.

Usage

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 calls useIpfs to retrieve the id of the node
  • useIpfsFactory.js initialises and closes the IPFS local node
  • useIpfs.js does the actual calls to IPFS to retrieve the property specified in argument (here the retrieved property is id, requested from App.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.

Screen shot of the js ipfs node id info

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

References

Documentation

Contributing

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.

  1. Fork the IPFS Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -a -m 'feat: add some amazing feature')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Want to hack on IPFS?

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