# Hosting your NFT on IPFS

If you don't know it yet, having an NFT does not mean that the NFT's file is uploaded as-is on the blockchain.  \
Rather, an NFT corresponds to a blockchain block that contains a certain token. This token stores a "pointer" or link, called `tokenURI`, which contains the online address to a metadata file, which itself references the media file using another URI.

Because of the peer-to-peer nature of the blockchain, you cannot just host your NFT file and its metadata file on any web hosting service. Your `tokenURI` needs to stay permanent (or "immutable") and portable across apps and marketplaces, for as long as can be, possibly forever.

This is where IPFS enters the scene.

## **About IPFS**

[IPFS](https://ipfs.tech/), for InterPlanetary File System, is a decentralised file network which servers the purpose of hosting and sharing data across distributed networks. NFT platforms can fetch data from IPFS instead of relying on a single server, and the IPFS protocol makes it "feel" like all hosted files are local.

{% hint style="success" %}
**Do I need to learn about IPFS right now?**

It depends on your chosen method to mint your NFT:

* Using vanilla code (such as [viem](https://viem.sh/) or [ethers](https://ethers.org/)): \
  **Yes**, you need a valid `tokenURI` (e.g., `ipfs://.../metadata.json`) beforehand.
* Through a dashboard such as [thirdweb](https://thirdweb.com/): \
  **No**. Uploading to IPFS is built in. You can still paste an existing `ipfs://...` if you have one in the NFT parameters.
* Using most Web3 SDKs (such as [Rarible's Multichain SDK](https://docs.rarible.org/reference/getting-started)): \
  **Yes**, they will expect a URI. Some tools might help with uploads, but not most.
  {% endhint %}

The IPFS website has [an extensive page on NFT Storing best practices](https://docs.ipfs.tech/how-to/best-practices-for-nft-data/#types-of-ipfs-links-and-when-to-use-them).

## Details of NFT upload

When uploading your NFT, you need to perform two uploads to the Content Identifier (CID) that IPFS generates for you:

* The content itself, for which IPFS returns an IPFS URL for the hosted file.
* The metadata file, which references the CID of the media file, and must contain the IPFS URL for the file.

Both are to be uploaded on IPFS under the same CID.&#x20;

Ideally, your toolset takes this in charge so that you don't have to do it all manually.

For information purpose, here is what a minimal `metadata.json` file would look like:&#x20;

```json
{ 
    "name": "Stadium Pass #25456456", 
    "description": "PSG supporter entry ticket", 
    "image": "ipfs:///filename.png",           // for static images only!
    // "animation_url": "ipfs:///filename.mp4" // for video and audio files.
    "attributes": [
    { 
        "trait_type": "Tier", 
        "value": "Gold" 
    }] 
}
```

To learn more about NFT metadata structure (for instance, why you should use `image` for images and `animation_url`  for videos), we advise you to read this document from OpenSea:

{% embed url="<https://docs.opensea.io/docs/metadata-standards#metadata-structure>" %}

Note: *You are not supposed to write the metadata file from scratch!* \
Your toolset should be able to generate it for you.

{% hint style="success" %}
You can either [run your own IPFS node](https://docs.ipfs.tech/how-to/command-line-quick-start/), or pay for an IPFS-host, such as [Pinata](https://pinata.cloud/), which offers a free pricing plan that might be enough for your needs.&#x20;

Follow [Pinata's quick-start guide](https://docs.pinata.cloud/quickstart) in order to obtain your API credentials (consisting of an API key, an API secret, and a JWT token) and your Dedicated Gateway domain (for instance, `blue-genetic-quail-122.mypinata.cloud`).
{% endhint %}

As this documentation is not meant to describe everything about IPFS, we advise you to dive into the topic through online searches. You can start with this Pinata explainer:

{% embed url="<https://docs.pinata.cloud/ipfs-101/how-does-ipfs-work-with-nfts>" %}

... or this blogpost from thirdweb:

{% embed url="<https://blog.thirdweb.com/guides/securing-pinning-your-nft-with-ipfs/>" %}
