Skip to content

Example of publishing to IPNS using JS-IPFS

Notifications You must be signed in to change notification settings

ipfs-examples/js-ipfs-browser-ipns-publish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IPFS in JavaScript logo

Publish to IPNS

Publish to IPNS from the browser using ipfs-http-client


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:8888

Usage

This example is a demo web application that allows you to connect to a go-IPFS node, and publish your IPNS record to the go-DHT network but using your js-ipfs private key. We'll start two IPFS nodes; one in the browser and one on a go-Server. We'll use ipfs-http-client to connect to the go-Node to ensure our pubsub messages are getting through, and confirm the IPNS record resolves on the go-Node. We're aiming for something like this:

   +-----------+     websocket     +-----------+
   |           +------------------->           |
   |  js-ipfs  |      pubsub       |  go-ipfs  |
   |           <-------------------+           |
   +-----^-----+                   +-----^-----+
         |                               |
         | IPFS in browser               | HTTP API
         |                               |
+-------------------------------------------------+
|                     Browser                     |
+-------------------------------------------------+
|                   |         |                   |
|                   |         |                   |
|  IPFS direct      |         |  js-http-client   |
|  a.k.a. ipfsNode  |         |  a.k.a. ipfsAPI   |
|                   |         |                   |
+-------------------------------------------------+

Start two IPFS nodes

The first node is the js-ipfs made in the browser and the demo does that for you.

The second is a go-ipfs node on a server. To get our IPNS record to the DHT, we'll need a server running go-IPFS with the API enabled on port 5001.

Right now the easiest way to do this is to install and start a go-ipfs node.

Install and start the Go IPFS node

If you do not have the ipfs installed, head over to https://dist.ipfs.io/#go-ipfs and hit the "Download go-ipfs" button. Extract the archive and read the instructions to install.

After installation:

ipfs init
# Configure CORS to allow ipfs-http-client to access this IPFS node
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"*\"]"
# Configure go-ipfs to listen on a websocket address
npx json -I -f ~/.ipfs/config -e "this.Addresses.Swarm.push('/ip4/127.0.0.1/tcp/4003/ws')"
# Start the IPFS node, enabling pubsub and IPNS over pubsub
ipfs daemon --enable-pubsub-experiment --enable-namesys-pubsub

Open the demo in a browser and connect to the go-node

Now, open up the demo in a browser window.

In the "CONNECT TO GO-IPFS VIA API MULTIADDRESS" field enter /ip4/YourServerIP/tcp/5001 (where YourSeverIP is your server's IP address or use /dns4/yourdomain.com/tcp/5001) and click connect. Once it connects, put your go-IPFS websocket address in the next field /dns4/yourdomain.com/tcp/4003/wss/p2p/QmPeerIDHash and hit the second "Connect" button.

This connects the API to the go-Node and connects your js-IPFS node via websocket to the go-IPFS node so pubsub will work.

You can choose whether to publish this record under the PeerId of the node that is running in the browser ('self') or choose to add a custom key to the IPFS keychain and publish under that instead. Either should work.

Finally, enter /ipfs/QmSomeHash as the content you want to publish to IPNS. You should see the messages sent from the browser to the server appear in the logs below, ending with "Success, resolved" if it all worked.

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

About

Example of publishing to IPNS using JS-IPFS

Resources

Stars

Watchers

Forks