You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide explains how to host a website on Swarm using `swarm-cli` and make it accessible through [Ethereum Name Service (ENS)](https://ens.domains/).
9
+
There are two primary methods most developers should use for uploading a website to Swarm - `swarm-cli` and `bee-js`. Depending on the specific use case, it may make more sense to pick one or the other.
10
+
11
+
For a simple website such as a personal blog or company page, using `swarm-cli` is simplest and fastest way to get your site uploaded and accessible on Swarm.
12
+
13
+
However for developers who need finer grained control over the process or who wish to build a more complex application which require programmatically spinning up new pages, `bee-js` is required.
14
+
15
+
:::tip
16
+
The guides below assume you already have a registered ENS domain name. By using an ENS domain name, you can make your Swarm hosted website accessible through an easy to remember human-readable name rather than a Swarm hash. If you don't have an ENS domain name registered, you can get one using the official ENS application at [app.ens.domains](https://app.ens.domains/). Refer to their support section for a step-by-step guide to [register an ENS domain](https://support.ens.domains/en/articles/7882582-how-to-register-a-eth-name).
17
+
:::
18
+
19
+
:::tip FIX FOR ENS NOT WORKING ON LOCALHOST
20
+
If the site doesn’t load from localhost, it’s probably an with the resolver RPC (the RPC endpoint for the Ethereum node used to resolve your ENS domain name).
21
+
22
+
Some endpoints, such as:
23
+
24
+
```
25
+
https://cloudflare-eth.com
26
+
```
27
+
28
+
may not resolve properly on localhost.
29
+
30
+
As of the writing of this guide, both of these free and public endpoints work reliably for localhost resolution:
31
+
32
+
```
33
+
https://mainnet.infura.io/v3/<infura-api-key>
34
+
https://eth-mainnet.public.blastapi.io
35
+
```
36
+
37
+
Alternatively, you can run your own Ethereum node and use that as the RPC.
38
+
:::
10
39
11
40
## Host a Site With **swarm-cli**
12
41
@@ -18,15 +47,17 @@ This three part guide shows you how to get your website hosted on Swarm with jus
18
47
19
48
**Part three** shows you how to use feeds to make you website accessible at a static hash, and then use that hash to connect with your ENS domain. This is highly recommended for any site which will have future updates - without this step you would need to re-register your ENS domain every time you updated the site.
20
49
21
-
### 1. Upload & Access by Hash
22
-
23
-
#### Prerequisites
50
+
### Prerequisites
24
51
25
52
* A running Bee node (either a [standard installation](/docs/bee/installation/quick-start) or [Swarm Desktop](/docs/desktop/install))
* Your static website files (you can also use the example website files provided below)
57
+
* (Optional for part one - "Upload & Access by Hash") An ENS domain which you [previously registered](https://support.ens.domains/en/articles/7882582-how-to-register-a-eth-name)
58
+
59
+
### 1. Upload & Access by Hash
60
+
30
61
31
62
You can download the example website files from the [ethersphere/examples](https://github.com/ethersphere/examples/tree/main/basic-static-website) repository.
32
63
@@ -122,26 +153,6 @@ or through your own node:
122
153
http://localhost:1633/bzz/yourname.eth/
123
154
```
124
155
125
-
:::tip
126
-
If the site doesn’t load from localhost, it’s probably an with the resolver RPC (the RPC endpoint for the Ethereum node used to resolve your ENS domain name).
127
-
128
-
Some endpoints, such as:
129
-
130
-
```
131
-
https://cloudflare-eth.com
132
-
```
133
-
134
-
may not resolve properly on localhost.
135
-
136
-
As of the writing of this guide, both of these free and public endpoints work reliably for localhost resolution:
137
-
138
-
```
139
-
https://mainnet.infura.io/v3/<infura-api-key>
140
-
https://eth-mainnet.public.blastapi.io
141
-
```
142
-
143
-
Alternatively, you can run your own Ethereum node and use that as the RPC.
It may take a few minutes for caches to reload and make your changes accessible, especially with ENS gateway services like `eth.limo` and `bzz.link`.
329
-
:::
340
+
:::
341
+
342
+
## Host a Website with **bee-js**
343
+
344
+
This guide explains how to host a website on Swarm using the `bee-js` JavaScript SDK instead of the CLI.
345
+
346
+
For developers building apps, tools, or automated deployments, `bee-js` offers programmatic control over uploading and updating content on Swarm. This three part guide explains how to host your site on Swarm using `bee-js`:
347
+
348
+
1. Uploading a website and getting its Swarm hash.
349
+
2. Registering the hash with your ENS domain.
350
+
3. Using feeds to keep an ENS record up-to-date through a static reference.
351
+
352
+
### Prerequisites
353
+
354
+
* A running Bee node (either a [standard installation](/docs/bee/installation/quick-start) or [Swarm Desktop](/docs/desktop/install))
355
+
* A valid postage stamp batch
356
+
* Node.js (18+) and `@ethersphere/bee-js` installed in your project
357
+
* Static website files (HTML, CSS, etc.) - feel free to use the [provided example site](https://github.com/ethersphere/examples/tree/main/basic-static-website)
358
+
* (Optional for part one - "Upload & Access by Hash") An ENS domain which you [previously registered](https://support.ens.domains/en/articles/7882582-how-to-register-a-eth-name)
359
+
360
+
361
+
### 1. Upload and Access by Hash
362
+
363
+
Install bee-js:
364
+
365
+
```bash
366
+
npm install @ethersphere/bee-js
367
+
```
368
+
369
+
Website upload script:
370
+
371
+
```js
372
+
import { Bee } from"@ethersphere/bee-js";
373
+
374
+
constbee=newBee("http://localhost:1633");
375
+
constbatchId="<POSTAGE_BATCH_ID>"; // Replace with your batch ID
After running the script, copy the Swarm hash output to the console and then use it to open:
386
+
387
+
```
388
+
http://localhost:1633/bzz/<swarm-hash>/
389
+
```
390
+
391
+
### 2. (Recommended) Connect Site to ENS Domain
392
+
393
+
*These steps are identical to
394
+
395
+
Once the site is uploaded, you can make it accessible via an easy to remember ENS domain name:
396
+
397
+
```
398
+
https://yourname.eth.limo/
399
+
https://yourname.bzz.link/
400
+
```
401
+
402
+
or through your own node:
403
+
404
+
```
405
+
http://localhost:1633/bzz/yourname.eth/
406
+
```
407
+
408
+
409
+
#### Using the Official ENS Guide
410
+
411
+
The ENS team provides a clear walkthrough with screenshots showing how to add a content hash to your domain with their [easy to use app](https://app.ens.domains/):
412
+
413
+
[How to add a Decentralized website to an ENS name](https://support.ens.domains/en/articles/12275979-how-to-add-a-decentralized-website-to-an-ens-name)
414
+
415
+
The guide covers:
416
+
417
+
* Opening your ENS domain in the ENS Manager
418
+
* Navigating to the Records tab
419
+
* Adding a Content Hash
420
+
* Confirming the transaction
421
+
422
+
423
+
#### Swarm-Specific Step
424
+
425
+
When you reach Step 2 in the ENS guide (“Add content hash record”), enter your Swarm reference in the following format:
0 commit comments