Skip to content

Commit b219b4e

Browse files
committed
Move publishing guide to how-to
1 parent dbe2740 commit b219b4e

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

docs/.vuepress/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ module.exports = {
237237
'/how-to/browser-tools-frameworks'
238238
]
239239
},
240+
{
241+
title: 'IPNS and mutability',
242+
sidebarDepth: 1,
243+
collapsable: false,
244+
children: [
245+
'/how-to/publish-ipns'
246+
]
247+
},
240248
{
241249
title: 'IPFS Companion',
242250
sidebarDepth: 1,

docs/how-to/publish-ipns.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: Publishing IPNS names
3+
description: Learn how to publish IPNS names with Kubo and js-ipfs
4+
---
5+
6+
# Publishing IPNS names
7+
8+
IPNS names can be published from both the command line and programmatically.
9+
10+
- [Publishing IPNS names with Kubo](#publishing-ipns-names-with-kubo)
11+
- [Publishing IPNS names programmatically with JS-IPFS](#publishing-ipns-names-programmatically-with-js-ipfs)
12+
13+
## Publishing IPNS names with Kubo
14+
15+
1. Start your IPFS daemon, if it isn't already running:
16+
17+
```shell
18+
ipfs daemon
19+
```
20+
21+
1. Open another command line window and create the file that you want to set up with IPNS. For the tutorial, we're just going to create a simple _hello world_ file:
22+
23+
```shell
24+
echo "Hello IPFS" > hello.txt
25+
```
26+
27+
1. Add your file to IPFS:
28+
29+
```shell
30+
ipfs add --cid-version 1 hello.txt
31+
32+
> added bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 hello.txt
33+
> 11 B / 11 B [=====================================================] 100.00%
34+
```
35+
36+
Take note of the CID output by IPFS.
37+
38+
1. Use `cat` and the CID you just got from IPFS to view the file again:
39+
40+
```shell
41+
ipfs cat bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244
42+
43+
> Hello IPFS
44+
```
45+
46+
1. Publish your CID to IPNS:
47+
48+
```shell
49+
ipfs name publish /ipfs/bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244
50+
51+
> Published to k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l: /ipfs/bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244
52+
```
53+
54+
`k51...` is the public key or IPNS name of the IPFS you are running. You can now change the file repeatedly, and, even though the CID changes when you change the file, you can continue to access it with this key.
55+
56+
1. You can view your file by going to `https://ipfs.io/ipns/k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l`:
57+
58+
```shell
59+
curl https://ipfs.io/ipns/k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l
60+
61+
> Hello IPFS
62+
```
63+
64+
1. Make a change to your file, add it to IPFS, and update your IPNS:
65+
66+
```shell
67+
echo "Hello again IPFS" > hello.txt
68+
ipfs add hello.txt
69+
70+
> added bafkreidbbor7mvra2xzzl4kmr2sxrtkzaxlzs6rsr5ktgmbtousuzrhlxq hello.txt
71+
> 17 B / 17 B [=====================================================] 100.00%
72+
73+
ipfs name publish bafkreidbbor7mvra2xzzl4kmr2sxrtkzaxlzs6rsr5ktgmbtousuzrhlxq
74+
75+
> Published to k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l: /ipfs/bafkreidbbor7mvra2xzzl4kmr2sxrtkzaxlzs6rsr5ktgmbtousuzrhlxq
76+
```
77+
78+
1. You can now go back to `https://ipfs.io/ipns/k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l` to view your updated file using the same address:
79+
80+
```shell
81+
curl https://ipfs.io/ipns/k51qzi5uqu5dgy6fu9073kabgj2nuq3qyo4f2rcnn4380z6n8i4v2lvo8dln6l
82+
83+
> Hello again IPFS
84+
```
85+
86+
You can view the CID of the file associated with your `k5` key by using `name resolve`:
87+
88+
```shell
89+
ipfs name resolve
90+
91+
> /ipfs/bafkreidbbor7mvra2xzzl4kmr2sxrtkzaxlzs6rsr5ktgmbtousuzrhlxq
92+
```
93+
94+
To use a different `k5` key, first create one using `key gen test`, and use the `--key` flag when calling `name publish`:
95+
96+
```shell
97+
ipfs key gen SecondKey
98+
99+
> k51qzi5uqu5dh5kbbff1ucw3ksphpy3vxx4en4dbtfh90pvw4mzd8nfm5r5fnl
100+
101+
ipfs name publish --key=SecondKey /ipfs/bafybeicklkqcnlvtiscr2hzkubjwnwjinvskffn4xorqeduft3wq7vm5u4
102+
103+
> Published to k51qzi5uqu5dh5kbbff1ucw3ksphpy3vxx4en4dbtfh90pvw4mzd8nfm5r5fnl: /ipfs/bafybeicklkqcnlvtiscr2hzkubjwnwjinvskffn4xorqeduft3wq7vm5u4
104+
```
105+
106+
## Publishing IPNS names programmatically with JS-IPFS
107+
108+
With [ipfs-core](https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-core#readme) (a full IPNS node in JavaScript) you can you can publish an IPNS name as follows:
109+
110+
```javascript
111+
import * as IPFS from 'ipfs-core'
112+
113+
const ipfs = await IPFS.create()
114+
115+
// The address of your files.
116+
const addr = '/ipfs/bafkreidbbor7mvra2xzzl4kmr2sxrtkzaxlzs6rsr5ktgmbtousuzrhlxq'
117+
118+
ipfs.name.publish(addr, options).then(function (res) {
119+
// You now receive a res which contains two fields:
120+
// - name: the name under which the content was published.
121+
// - value: the "real" address to which Name points.
122+
console.log(`https://ipfs.io/ipns/${res.name}`)
123+
})
124+
```
125+
126+
By default, `ipfs.name.publish` will use the Peer ID and set the lifetime to 24 hours. To learn more about the full API, check out the [API docs](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/NAME.md#ipfsnamepublishvalue-options).
127+
128+
:::warning
129+
Note that when using `ipfs-core`, you're instantiating a full IPFS node. For your IPNS record to propagate through the network, it needs to be connected to other peers. Typically this is not a problem, however, if you're running `ipfs-core` in the browser, you may want to connect it to a long-running IPFS node to ensure it successfully propagates due to [browser connectivity limitations.](https://github.com/ipfs/js-ipfs/blob/master/docs/BROWSERS.md#limitations-of-the-browser-context)
130+
:::

0 commit comments

Comments
 (0)