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
Copy file name to clipboardExpand all lines: docs/how-to/ipfs-in-web-apps.md
+23-3Lines changed: 23 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: IPFS in web applications
3
-
description: How to develop applications that use IPFS in web browsers, including IPFS retrieval and pinning in browsers using implementations such as Helia.
3
+
description: How to develop applications that use IPFS on the Web including addressing by CID, merkleizing, retrieval, providing, and CAR files with Helia.
4
4
---
5
5
6
6
# IPFS in web-applications and resource-constrained environments
@@ -23,7 +23,7 @@ There are good reasons for this like security and resource management, but ultim
23
23
24
24
As a developer, IPFS exposes three main operations for interacting with the network:
25
25
26
-
-**Addressing data with CIDs** (also known as merkleizing): taking arbitrary data and encoding so its addressable by CID. For example, given a file and encoding it so it can be addressed by a CID.
26
+
-**Addressing data with CIDs** (also known as **merkleizing**): taking arbitrary data and encoding so its addressable by CID. For example, given a directory of files, merkleizing it so it can be addressed and retrieved by CID.
27
27
-**Retrieving data by CID**: given a CID, IPFS finds providers (peers who share the block), connects to them, fetches the blocks, and verifies that the retrieved data is what the CID represents.
28
28
-**Providing data by CID**: making data addressed by a CID retrievable by other peers, either by running a node or with a pinning service.
29
29
@@ -95,7 +95,7 @@ Instead, you should provide data from a long-running server that runs reliably a
95
95
96
96
The Content Archive format is a way of packaging up content addressed data into archive files that can be easily stored and transferred over the network. You can think of them like TAR files that are designed for storing collections of content addressed data.
97
97
98
-
So why would you want to use CAR files?
98
+
**So why would you want to use CAR files?**
99
99
100
100
One of the main reasons is related to [CID determinism](#cid-determinism). As mentioned above, the same data can result in different CIDs, which can make it difficult to verify data without its content addressed representation. By packaging up the data into a CAR file, you can upload the CAR to multiple pinning services and nodes knowing they are providing the same CIDs
101
101
@@ -105,3 +105,23 @@ Car files are a great way to store content-addressed data in a way that is easy
105
105
See the Pen <a href="https://codepen.io/2color/pen/EaYoegX">
106
106
CAR export with Helia and dag-cbor</a> by Daniel Norman (<a href="https://codepen.io/2color">@2color</a>)
107
107
</iframe>
108
+
109
+
At the time of writing, not all pinning services support CAR files, but it is a feature that is being added to more and more services. Therefore, it is a good idea to check the documentation for the pinning service you are using to see if it supports CAR files.
110
+
111
+
## Conclusion
112
+
113
+
This guide has covered the essential aspects of using IPFS in web applications:
114
+
115
+
- The main operations: addressing/merkleizing data with CIDs, retrieving data, and providing data.
116
+
- The challenges and limitations of using IPFS in browser environments.
117
+
- Practical examples using modern tools like [Helia](https://github.com/ipfs/helia) and [Verified Fetch](https://www.npmjs.com/package/@helia/verified-fetch).
118
+
- Best practices for handling data persistence through pinning services and CAR files.
119
+
120
+
When building web applications with IPFS, remember these key takeaways:
121
+
122
+
1. Use client-side merkleization (addressing) when onboarding new data to IPFS, but rely on pinning services or IPFS nodes for providing data.
123
+
1. Be mindful of CID determinism when working with files and structured data.
124
+
1. Consider using CAR files where possible for storage and transport of content-addressed data.
125
+
1. Use Verified Fetch for simple retrieval or Helia for more complex IPFS interactions.
126
+
127
+
By following these guidelines, you can reap the benefits of IPFS while working within the constraints of the web.
0 commit comments