0Pricing
Web3 & DApp Development Fundamentals · Lektion

DApp-Assets speichern

Lernen Sie, Frontend-Assets von DApps, NFT-Metadaten und andere Dateien mithilfe von IPFS zur Dezentralisierung hochzuladen und abzurufen.

DApp-Assets speichern ist eine kostenlose Web3 & DApp Development Fundamentals-Lektion auf CoddyKit. Dies ist Lektion 2 von 3. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Web3 & DApp Development Fundamentals-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Web3 & DApp Development Fundamentals-Kurs umfasst insgesamt 3 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Why Decentralize DApp Assets?

Traditional web applications host their front-ends (like HTML, CSS, and JavaScript files) on centralized servers. This means if that server goes down or is censored, the application becomes inaccessible.

Decentralized Applications (DApps) aim for full decentralization, but if your smart contract is on a blockchain while your user interface (UI) is on a single cloud server, is it truly decentralized? This lesson explores how IPFS helps.

Hosting Your DApp's UI on IPFS

IPFS provides a robust solution for hosting your entire DApp front-end. This includes all your static files: HTML pages, CSS stylesheets, JavaScript code, and images.

  • Once uploaded, the entire DApp content (or individual files) receives a unique Content Identifier (CID).
  • Users can then access your DApp directly via an IPFS gateway URL, making it highly censorship-resistant and always available, as long as it's pinned on the network.

CIDs: Content's Digital Fingerprint

As you learned in the previous lesson, IPFS uses Content Identifiers (CIDs) instead of location-based addresses.

  • A CID is a cryptographic hash of the content itself. This means if even a single byte of the content changes, its CID will also change.
  • This content addressing ensures data integrity and immutability. You can always verify that you are accessing the exact file you expect, free from tampering.

Uploading Assets to IPFS

To place your files onto the IPFS network, you typically use the IPFS command-line interface (CLI) or a client library in your code.

The ipfs add command is commonly used. It takes a file or a directory and returns its unique CID.

For example, to upload a folder containing your DApp's front-end:

ipfs add my_dapp_folder/

This command would process your folder and output a CID that represents its entire content.

Ensuring Data Stays Available (Pinning)

When you use ipfs add, your content is initially stored only on your local IPFS node. For others to reliably access it, that content needs to be "pinned."

  • Pinning is the process of telling an IPFS node to keep a copy of specific content indefinitely, preventing it from being garbage collected.
  • You can pin content to your own IPFS node, or more commonly for DApps, use a third-party "pinning service."
  • Pinning services provide dedicated infrastructure to host your content, ensuring high availability and uptime for your DApp's assets.

Decentralizing NFT Metadata

Non-Fungible Tokens (NFTs) often represent unique digital assets like images, videos, or audio. The NFT smart contract itself doesn't store the asset directly.

Instead, the smart contract typically stores a URI (Uniform Resource Identifier) that points to the asset's metadata. Storing this metadata (and often the asset itself) on IPFS is crucial:

  • It prevents the metadata from being altered or disappearing if a centralized server hosting it goes offline.
  • It ensures the NFT's value is tied to a persistent, verifiable piece of data.

Anatomy of NFT Metadata (JSON)

NFT metadata is typically a JSON (JavaScript Object Notation) file that provides descriptive information about the digital asset.

It usually includes details such as the asset's name, description, and a link to the actual media file (which is often also stored on IPFS).

Here's a common example structure:

{
  "name": "My Awesome NFT",
  "description": "A unique digital collectible.",
  "image": "ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26h7y3g7o...",
  "attributes": [
    { "trait_type": "Background", "value": "Blue" }
  ]
}

The image field, for instance, uses an ipfs:// URI scheme to point directly to the asset's CID on IPFS.

How Users Access IPFS Content

Most end-users don't run their own IPFS nodes. So, how do they access content stored on IPFS?

  • They access it through "IPFS Gateways."
  • An IPFS gateway is a regular web server that acts as a bridge. It fetches content from the IPFS network on demand and serves it over standard HTTP to web browsers.
  • Popular public gateways include https://cloudflare-ipfs.com/ipfs/<your-CID> or https://ipfs.io/ipfs/<your-CID>.

DApps Retrieving IPFS Data

Your DApp's front-end code (typically written in JavaScript) can easily retrieve content from IPFS using CIDs and gateways.

  • The DApp constructs a standard web URL using the IPFS gateway address and the content's CID.
  • It then uses standard web requests (like the JavaScript fetch API) to retrieve the content, just like any other web resource.

Here's a conceptual JavaScript example:

const cid = "bafybeigdyrzt5sfp7udm7hu...";
const gatewayUrl = `https://ipfs.io/ipfs/${cid}`;

fetch(gatewayUrl)
  .then(response => response.json())
  .then(data => console.log("NFT Metadata:", data))
  .catch(error => console.error("Error fetching data:", error));

IPFS Storage Check

When building a DApp, why is it beneficial to store your front-end assets (like HTML, CSS, JavaScript) and NFT metadata on IPFS instead of a traditional centralized web server?

Recap: Storing DApp Assets

You've successfully learned how IPFS provides a decentralized and robust way to store critical DApp components, including front-end assets and NFT metadata.

  • We covered the practical aspects of uploading files using ipfs add and the crucial role of pinning services for content persistence.
  • You now understand how CIDs ensure immutability and how IPFS gateways enable users to access this decentralized content via standard web browsers.
  • This knowledge is fundamental to building DApps that are resilient, censorship-resistant, and truly decentralized.

Next, we'll explore Filecoin, which builds upon IPFS to offer an incentivized and verifiable layer for long-term, persistent storage solutions.

Häufig gestellte Fragen

Ist die Lektion „DApp-Assets speichern“ kostenlos?

Ja — der vollständige Text von „DApp-Assets speichern“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Web3 & DApp Development Fundamentals-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Web3 & DApp Development Fundamentals-Kurs umfasst insgesamt 3 Lektionen.

Was lerne ich in „DApp-Assets speichern“?

Lernen Sie, Frontend-Assets von DApps, NFT-Metadaten und andere Dateien mithilfe von IPFS zur Dezentralisierung hochzuladen und abzurufen. Du übst Web3 & DApp Development Fundamentals mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Web3 & DApp Development Fundamentals zu starten?

Keine Vorkenntnisse erforderlich. Web3 & DApp Development Fundamentals auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 3.

Wie lange dauert die Lektion „DApp-Assets speichern“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Web3 & DApp Development Fundamentals-Lektion Code schreiben und ausführen?

Ja. Jede Web3 & DApp Development Fundamentals-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Einführung in IPFS
  2. DApp-Assets speichern
  3. Filecoin und dezentrale Speicherung
← Zurück zu Web3 & DApp Development Fundamentals