{"id":18584436,"url":"https://github.com/ipfs-examples/js-ipfs-circuit-relaying","last_synced_at":"2025-05-16T05:33:11.329Z","repository":{"id":104999590,"uuid":"376796250","full_name":"ipfs-examples/js-ipfs-circuit-relaying","owner":"ipfs-examples","description":"Example of circuit relaying using JS-IPFS","archived":false,"fork":false,"pushed_at":"2025-05-01T07:35:59.000Z","size":3076,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-01T08:30:22.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipfs-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-14T11:15:33.000Z","updated_at":"2025-05-01T07:36:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"62b5b65e-db32-46a4-8afe-ccd573bfd64b","html_url":"https://github.com/ipfs-examples/js-ipfs-circuit-relaying","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"ipfs-examples/example-fork-go-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-circuit-relaying","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-circuit-relaying/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-circuit-relaying/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-examples%2Fjs-ipfs-circuit-relaying/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs-examples","download_url":"https://codeload.github.com/ipfs-examples/js-ipfs-circuit-relaying/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254473839,"owners_count":22077184,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T00:27:30.514Z","updated_at":"2025-05-16T05:33:11.312Z","avatar_url":"https://github.com/ipfs-examples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://js.ipfs.io\" title=\"JS IPFS\"\u003e\n    \u003cimg src=\"https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png\" alt=\"IPFS in JavaScript logo\" width=\"244\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003e\u003cb\u003eIPFS Circuit Relay\u003c/b\u003e\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003e\u003ci\u003eCircuit relay, where it fits in the stack and how to use it.!\u003c/i\u003e\u003c/b\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png\" width=\"200\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/ipfs/js-ipfs/tree/master/docs\"\u003eExplore the docs\u003c/a\u003e\n  ·\n  \u003ca href=\"https://codesandbox.io/\"\u003eView Demo\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/ipfs-examples/js-ipfs-examples/issues\"\u003eReport Bug\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/ipfs-examples/js-ipfs-examples/issues\"\u003eRequest Feature/Example\u003c/a\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Table of Contents](#table-of-contents)\n- [About The Project](#about-the-project)\n- [Getting Started](#getting-started)\n  - [Prerequisites](#prerequisites)\n  - [Installation and Running example](#installation-and-running-example)\n- [Usage](#usage)\n  - [So what is a `circuit-relay` and what do we need it for?](#so-what-is-a-circuit-relay-and-what-do-we-need-it-for)\n    - [How does circuit relay work?](#how-does-circuit-relay-work)\n    - [What's up with this `HOP` and `STOP`?](#whats-up-with-this-hop-and-stop)\n    - [A few caveats (and features)](#a-few-caveats-and-features)\n    - [A word on circuit relay addresses](#a-word-on-circuit-relay-addresses)\n  - [Step-by-Step example](#step-by-step-example)\n  - [1. Configure and run the js or go ipfs node](#1-configure-and-run-the-js-or-go-ipfs-node)\n    - [Setting up a `go-ipfs` node](#setting-up-a-go-ipfs-node)\n    - [Setting up a `js-ipfs` node](#setting-up-a-js-ipfs-node)\n    - [Starting the relay node](#starting-the-relay-node)\n  - [2. Configure and run the bundled example](#2-configure-and-run-the-bundled-example)\n    - [3. Connect the two browser nodes to the circuit relay](#3-connect-the-two-browser-nodes-to-the-circuit-relay)\n  - [4. Dial the two browser nodes using a `/p2p-circuit` address](#4-dial-the-two-browser-nodes-using-a-p2p-circuit-address)\n  - [5. Send data browser to browser.](#5-send-data-browser-to-browser)\n  - [So what just happened?](#so-what-just-happened)\n- [References](#references)\n- [Documentation](#documentation)\n- [Contributing](#contributing)\n- [Want to hack on IPFS?](#want-to-hack-on-ipfs)\n\n## About The Project\n\n- Read the [docs](https://github.com/ipfs/js-ipfs/tree/master/docs)\n- Look into other [examples](https://github.com/ipfs-examples/js-ipfs-examples) to learn how to spawn an IPFS node in Node.js and in the Browser\n- Consult the [Core API docs](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api) to see what you can do with an IPFS node\n- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it\n- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs\n- Check out https://docs.ipfs.io for tips, how-tos and more\n- See https://blog.ipfs.io for news and more\n- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io\n\n## Getting Started\n\n### Prerequisites\n\nMake sure you have installed all of the following prerequisites on your development machine:\n\n- Git - [Download \u0026 Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.\n- Node.js - [Download \u0026 Install Node.js](https://nodejs.org/en/download/) and the npm package manager.\n- IPFS Daemon - [Install js-ipfs](https://github.com/ipfs/js-ipfs) or [Download \u0026 Install IPFS Desktop](https://docs.ipfs.io/install/ipfs-desktop/) that will run the go version of IPFS or 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.\n\n### Installation and Running example\n\n```console\n\u003e npm install\n\u003e npm start\n```\n\nNow open your browser at `http://localhost:8888`\n\n## Usage\n\n### So what is a `circuit-relay` and what do we need it for?\n\nIn p2p networks there are many cases where two nodes can't talk to each other directly. That may happen because of network topology, i.e. NATs, or execution environments - for example browser nodes can't connect to each other directly because they lack any sort of socket functionality and relaying on specialized rendezvous nodes introduces an undesirable centralization point to the network. A `circuit-relay` is a way to solve this problem - it is a node that allows two other nodes that can't otherwise talk to each other, use a third node, a relay to do so.\n\n#### How does circuit relay work?\n\nHere is a simple diagram depicting how a typical circuit-relay connection might look:\n\n```\n+---------------------+         |          |         +---------------------+\n|       Node A        |---------\u003e FIREWALL \u003c---------|        Node B       |\n+----------^----------+         |          |         +----------^----------+\n           |                                                    |\n           |               +---------------------+              |\n           +---------------\u003e   Circuit Relay     \u003c--------------+\n                           +---------------------+\n```\n\n`Node A` tries to connect to `Node B` but, UH-OH! There is a firewall in between that's preventing it from happening. If both `Node A` and `Node B` know about a relay, they can use it to establish the connection.\n\nThis is what it looks like, in simplified steps:\n\n1. `Node A` tries to connect to `Node B` over one of its known addresses\n2. Connection fails because of firewall/NAT/incompatible transports/etc...\n3. Both `Node A` and `Node B` know of the same relay - `Relay`\n4. `Node A` falls back to dialing over `Relay` to `Node B` using its `'/p2p-circuit'` address, which involves:\n   1. `Node A` sends a `HOP` request to `Relay`\n   2. `Relay` extracts the destination address, figures out that a circuit to `Node B` is being requested\n   3. `Relay` sends a `STOP` request to `Node B`\n   4. `Node B` responds with a `SUCCESS` message\n   5. `Relay` proceed to create a circuit over the two nodes\n5. `Node A` and `Node B` are now connected over `Relay`\n\nThat's it!\n\n\u003e For a more in-depth explanation take a look at the [relay spec](https://github.com/libp2p/specs/blob/master/relay/README.md) and `js-libp2p-circuit` [README](https://github.com/libp2p/js-libp2p-circuit/blob/master/README.md)\n\n#### What's up with this `HOP` and `STOP`?\n\nCircuit relay consists of two logical parts — dialer/listener and relay (`HOP`). The listener is also known as the `STOP` node. Each of these — dial, listen, and relay — happen on a different node. If we use the nodes from the above example, it looks something like this:\n\n- The `dialer` knows how to dial a `relay` (`HOP`) - `Node A`\n- The `relay` (`HOP`) knows how to contact a destination node (`STOP`) and create a circuit - `Relay` node\n- The `listener` (`STOP`) knows how to process relay requests that come from the relay (`HOP`) node - `Node B`\n\n_Fun fact - the `HOP` and `STOP` names are also used internally by circuit to identify the network message types._\n\n#### A few caveats (and features)\n\nThere are a couple of caveats and features to be aware of:\n\n- A `Relay` will only work if it already has a connection to the `STOP` node\n- No `multihop` dialing is supported. It's a feature planed for upcoming releases (no date on this one)\n  - `multihop` dialing is when several relays are used to establish the connection\n- It is possible to use explicit relay addresses to connect to a node, or even to listen for connections on. See next section to learn how to do this.\n\n#### A word on circuit relay addresses\n\nA circuit relay address is a [multiaddress](https://multiformats.io/multiaddr/) that describes how to either connect to a peer over a relay (or relays), or allow a peer to announce it is reachable over a particular relay or any relay it is already connected to.\n\nCircuit relay addresses are very flexible and can describe many different aspects of how to establish the relayed connection. In its simplest form, it looks something like this:\n\n- `/p2p-circuit/p2p/QmPeer`\n\nIf we want to be specific as to which transport we want to use to establish the relay, we can encode that in the address as well:\n\n- `/ip4/127.0.0.1/tcp/65000/p2p/QmRelay/p2p-circuit/p2p/QmPeer`\n\nThis tells us that we want to use `QmRelay` located at address 127.0.0.1 and port 65000.\n\n- `/ip4/127.0.0.1/tcp/65000/p2p/QmRelay/p2p-circuit/ip4/127.0.0.1/tcp/8080/ws/p2p/QmPeer`\n\nWe can take it a step further and encode the same information for the destination peer. In this case, we have it located at 127.0.0.1 on port 8080 and using a Web sockets transport!\n\n- `/ip4/127.0.0.1/tcp/65000/p2p/QmRelay/p2p-circuit`\n\nIf a node is configured with this address, it will use the specified host (`/ip4/127.0.0.1/tcp/65000/p2p/QmRelay`) as a relay and it will be reachable over this relay.\n\n- There could multiple addresses of this sort specified in the config, in which case the node will be reachable over all of them.\n- This is useful if, for example, the node is behind a firewall but wants to be reachable from the outside over a specific relay.\n\nOther use-cases are also supported by this scheme, e.g. we can have multiple hops (circuit-relay nodes) encoded in the address, something planed for future releases.\n\n### Step-by-Step example\n\nHere's what we are going to be doing, today:\n\n1. Install and configure `go-ipfs` and `js-ipfs` nodes\n2. Configure and run the js or go ipfs node\n3. Configure and run the bundled example\n4. Connect the two browser nodes to the circuit relay\n5. Dial the two browser nodes using a `/p2p-circuit` address\n6. Finally, send data from one browser using the bundled example!\n\n\u003e We should end up with something similar to the bellow screenshot after we've gone through all the steps:\n\n![](./img/img7.png)\n\n### 1. Configure and run the js or go ipfs node\n\nYou can use a `go-ipfs` or a `js-ipfs` node as a relay. We'll demonstrate how to set both up in this tutorial and we encourage you to try both out. That said, either js or go should do the trick!\n\n#### Setting up a `go-ipfs` node\n\nIn order to enable the relay functionality in `go-ipfs` we need to edit it's configuration file, located under `~/.ipfs/config`:\n\n```json\n  \"Swarm\": {\n    \"AddrFilters\": null,\n    \"ConnMgr\": {\n      \"GracePeriod\": \"20s\",\n      \"HighWater\": 900,\n      \"LowWater\": 600,\n      \"Type\": \"basic\"\n    },\n    \"DisableBandwidthMetrics\": false,\n    \"DisableNatPortMap\": false,\n    \"DisableRelay\": false,\n    \"EnableRelayHop\": true\n  }\n```\n\nThe two options we're looking for are `DisableRelay` and `EnableRelayHop`. We want the former (`DisableRelay`) set to `false` and the latter (`EnableRelayHop`) to `true`, just like in the example above. That should set our go node as a relay.\n\nWe also need to make sure our go node can be dialed from the browser. For that, we need to enable a transport that both the browser and the go node can communicate over. We will use the web sockets transport, although there are others that can be used, such as `webrtc-star` and `websocket-star`. To enable the transport and set the interface and port we need to edit the `~/.ipfs/config` one more time. Let's find the `Swarm` array and add our desired address there. I picked `/ip4/0.0.0.0/tcp/4004/ws` because it is a port I know is not being used by anything on my machine, but we can also use port `0` so that the OS chooses a random available port for us — either one should work.\n\n```json\n  \"Swarm\": [\n    \"/ip4/0.0.0.0/tcp/4001\",\n    \"/ip4/0.0.0.0/tcp/4004/ws\",\n    \"/ip6/::/tcp/4001\"\n  ],\n```\n\nThe config should look similar to the above snippet after we've edited it.\n\n#### Setting up a `js-ipfs` node\n\nWe need to go through similar steps to enable circuit relay in `jsipfs`. However, the config options are slightly different — that should change once this feature is not marked as experimental, but for now we have to deal with two different sets of options.\n\nJust as we did with `go-ipfs`, go ahead and edit `js-ipfs` config file located under `~/.jsipfs/config`. Let's add the following config:\n\n```js\n  \"relay\": {\n    \"enabled\": true,\n    \"hop\": {\n      \"enabled\": true\n    }\n  }\n```\n\nNote that we don't have to do anything to enable the `websocket` transport as it is enabled by default in `jsipfs`.\n\n#### Starting the relay node\n\nWe can start the relay nodes by either running `ipfs daemon` or `jsipfs daemon`:\n\n**go ipfs**\n\n```console\n$ ipfs daemon\nInitializing daemon...\nSwarm listening on /ip4/127.0.0.1/tcp/4001\nSwarm listening on /ip4/192.168.1.132/tcp/4001\nSwarm listening on /ip6/::1/tcp/4001\nSwarm listening on /p2p-circuit/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\nSwarm announcing /ip4/127.0.0.1/tcp/4001\nSwarm announcing /ip4/186.4.18.182/tcp/58986\nSwarm announcing /ip4/192.168.1.132/tcp/4001\nSwarm announcing /ip6/::1/tcp/4001\nAPI server listening on /ip4/127.0.0.1/tcp/5001\nGateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080\nDaemon is ready\n```\n\nIn the case of go ipfs, the crucial `/p2p/Qm...` part of the multiaddr might be missing. In that case, you can get it by running the `ipfs id` command.\n\n```console\n$ ipfs id\n{\n  \"ID\": \"QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\",\n  \"PublicKey\": \"CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC84qPFzqajCfnvaJunqt48S1LIBRthXV60q5QClL+dUfOOU/m7v1ZcpNhvFFUN6tVCDaoT5AxEv0czxZiVx/njl6FVIc6tE1J+HWpc8cbAXNY6QbbyzKl/rjp7V8/QClE0JqgjIk84wnWGTwFhOEt0hnpu2XFt9iHaenSfg3EAa8K9MlbxmbawuxNLJJf7VZXkJrUNl6WOglAVU8Sqc4QaahCLVK5Dzo98zDBq1KDBxMbUgH0LTqzr6i+saxkEHZmBKO+mMVT3LzOUx1DQR4pLAw1qgoJstsIZEaJ2XLh975IiI7OKqWYH7+3NyNK2sldJK/4Zko4rH3irmnkAxLcFAgMBAAE=\",\n  \"Addresses\": [\n          \"/ip4/127.0.0.1/tcp/4001/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\",\n          \"/ip4/192.168.1.132/tcp/4001/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\",\n          \"/ip6/::1/tcp/4001/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\",\n          \"/ip4/186.4.18.182/tcp/13285/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\",\n          \"/ip4/186.4.18.182/tcp/13285/p2p/QmY73BLYav2gYc9PCEnjQqbfSGiqFv3aMsRXNyKFGtUoGF\"\n  ],\n  \"AgentVersion\": \"go-ipfs/0.4.14-dev/cb5bb7dd8\",\n  \"ProtocolVersion\": \"ipfs/0.1.0\"\n}\n```\n\nWe can then grab the resolved multiaddr from the `Addresses` array — `/ip4/127.0.0.1/tcp/4004/ws/p2p/Qm...`. Let's note it down somewhere and move to the next step.\n\n**js ipfs**\n\n```console\n$ jsipfs daemon\nInitializing daemon...\nSwarm listening on /p2p-circuit/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nSwarm listening on /p2p-circuit/ip4/0.0.0.0/tcp/4002/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nSwarm listening on /p2p-circuit/ip4/127.0.0.1/tcp/4003/ws/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nSwarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nSwarm listening on /ip4/127.0.0.1/tcp/4002/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nSwarm listening on /ip4/192.168.1.132/tcp/4002/p2p/QmfQj8YwDdy1uP2DpZBa7k38rSGPvhHiC52cdAGWBqoVpq\nAPI is listening on: /ip4/127.0.0.1/tcp/5002\nGateway (readonly) is listening on: /ip4/127.0.0.1/tcp/9090\nDaemon is ready\n```\n\nLook out for an address similar to `/ip4/127.0.0.1/tcp/4003/ws/p2p/Qm...`. Note it down somewhere, and let's move on to the next step.\n\n### 2. Configure and run the bundled example\n\nNow that we have ipfs installed and initialized, let's set up the included example. This is a standard npm package, so the usual `npm install` should get us going. Let's `cd` into the `examples/circuit-relaying` directory.\n\nWe should be able to run the project with `npm start` and get output similar to:\n\n```sh\nnpm start\nServer running at http://localhost:8888\n```\n\nThe bundled example is a simple chat app that uses another cool ipfs feature - [pubsub](https://github.com/libp2p/specs/tree/master/pubsub). Let's open up a browser and paste the above url into the address bar. We should see something similar to the following image:\n\n![](./img/img1.png)\n\n#### 3. Connect the two browser nodes to the circuit relay\n\nIn order for our browser nodes to be able to messages each other, we need to get them connected. But to do that, we need to use a relay - browser nodes can't be connected directly because of lack of socket support.\n\nRemember the caveat above `Currently a Relay will only work if it already has a connection to the STOP node`? This means that we need to connect our browser nodes to the relay node first.\n\nHaving both browsers running side by side (as shown in the first screenshot), enter the `/ip4/127.0.0.1/tcp/4003/ws/p2p/...` address noted above into the `Connect to Peer` field and hit the `Connect` button:\n\n![](./img/img3.png)\n\nAfter connecting to the IPFS node, we should see the relay peer show up under the `Swarm Peers` box.\n\n![](./img/img4.png)\n\nLet's repeat the same steps with the second tab. Now, both of our browser nodes should be connected to the relay and we can move on to the next step.\n\n### 4. Dial the two browser nodes using a `/p2p-circuit` address\n\nNow that our browsers are both connected to the relay peer, let's get them connected to each other. Create the p2p circuit address as follows:\n\n```\n${RELAY_ADDR}/p2p-circuit/p2p/${PEER_ID}\n```\n\nHere `${RELAY_ADDR}` is the multiaddr of the circuit relay node that you pasted into the \"Connect to Peer\" box in step 3, and `${PEER_ID}` is the id of the node we wish to connect to which can be found in the \"Peer id\" box of the browser window.\n\nUse the id from the \"Peer id\" box in the second browser window in the relay address you paste into the first browser, then repeat this step using the relay address of the first window in the second.\n\n![](./img/img5.png)\n\nLet's hit the `Connect` button on each of the tabs and we should get the two browsers connected and join the chat room.\n\n![](./img/img6.png)\n\n### 5. Send data browser to browser.\n\nNow that we have the two browsers connected, let's try the app out. Type a few words in one of the browser windows and you should see them appear in the other as well!\n\n![](./img/img7.png)\n\nThats it!\n\n### So what just happened?\n\nGood question!\n\n- We used [js-ipfs](htpps://github.com/ipfs/js-ipfs) running in the browser with circuit relay enabled:\n  - _Notice the `relay.enabled` below_\n\nyou can find it in [src/app.js](src/app.js)\n\n```js\nconst ipfs = await IPFS.create({\n  repo: repo(),\n  relay: {\n    enabled: true,\n    hop: {\n      enabled: true,\n    },\n  },\n  config: {\n    Bootstrap: [],\n  },\n});\n```\n\n- We connected the browser nodes to an external node over its websocket transport using the `/ip4/127.0.0.1/tcp/4003/ws/p2p/...` multiaddr. That external node happens to be a `HOP` node, meaning that it can relay connections for our browsers (and other nodes) allowing them to connect\n\n- And finally we connected the two browser nodes using the `/p2p-circuit/p2p/...` multiaddr. Take a look at the code below in [src/app.js](src/app.js#L103...L108) - lines 103-108\n\n```js\ntry {\n  await ipfs.swarm.connect(peer);\n} catch (err) {\n  return console.error(err);\n}\n$pAddrs.innerHTML += `\u003cli\u003e${peer.trim()}\u003c/li\u003e`;\n```\n\nThe above code snippet handles connecting to other nodes using `ipfs.swarm.connect`. Notice how there wasn't anything special we had to do to use the circuit once we had everything connected; all the magic is in the multiaddr! [Multiaddrs](https://multiformats.io/multiaddr/) are **AWESOME**!\n\nI encourage the reader to take a look at the bundled app code to see how the browser nodes get setup, suffice to say nothing changes from the perspective of using an `IPFS` node in js code, apart from the new `EXPERIMENTAL` options.\n\nFinally, a side note on [pubsub](https://github.com/libp2p/specs/blob/master/pubsub/README.md). We've used the amazing [ipfs-pubsub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) module, to enable the chat functionality. Make sure to take a look at the demo [video](https://www.youtube.com/watch?v=Nv_Teb--1zg) that explains how pubsub works and how it can be used to build other applications!\n\nCheers!\n\n_For more examples, please refer to the [Documentation](#documentation)_\n\n## References\n\n- Documentation:\n  - [IPFS CONFIG](https://github.com/ipfs/js-ipfs/blob/master/docs/CONFIG.md)\n  - [MISCELLANEOUS](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/MISCELLANEOUS.md)\n  - [SWARM](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/SWARM.md)\n  - [PUBSUB](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PUBSUB.md)\n  - [LIBP2P CONFIG](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md)\n- Tutorials:\n  - [libp2p](https://proto.school/introduction-to-libp2p)\n  - [Anatomy of a CID](https://proto.school/anatomy-of-a-cid)\n\n## Documentation\n\n- [Config](https://docs.ipfs.io/)\n- [Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api)\n- [Examples](https://github.com/ipfs-examples/js-ipfs-examples)\n- [Development](https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md)\n- [Tutorials](https://proto.school)\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the IPFS Project\n2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)\n3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`)\n4. Push to the Branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Want to hack on IPFS?\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)\n\nThe IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:\n\nRead the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md).\n\n- **Check out existing issues** The [issue list](https://github.com/ipfs/js-ipfs/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge\n- **Look at the [IPFS Roadmap](https://github.com/ipfs/roadmap)** This are the high priority items being worked on right now\n- **Perform code reviews** More eyes will help\n  a. speed the project along\n  b. ensure quality, and\n  c. reduce possible future bugs.\n- **Add tests**. There can never be enough tests.\n- **Join the [Weekly Core Implementations Call](https://github.com/ipfs/team-mgmt/issues/992)** it's where everyone discusses what's going on with IPFS and what's next\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-examples%2Fjs-ipfs-circuit-relaying","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs-examples%2Fjs-ipfs-circuit-relaying","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-examples%2Fjs-ipfs-circuit-relaying/lists"}