> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/th/phatthana/sung-khuen/nft/host-ipfs.md).

# Host NFT บน IPFS

หากคุณยังไม่ทราบ การมี NFT ไม่ได้หมายความว่าไฟล์ของ NFT จะถูกอัปโหลดโดยตรงลงบน blockchain\
แต่ NFT คือบล็อกบน blockchain ที่เก็บ token หนึ่งตัว ซึ่ง token นั้นจะเก็บ "ตัวชี้" หรือลิงก์ที่เรียกว่า `tokenURI` ซึ่งมีที่อยู่ออนไลน์ไปยังไฟล์ metadata และไฟล์ metadata นั้นจะอ้างอิงไปยังไฟล์มีเดียอีกทีผ่าน URI อีกรายการหนึ่ง

เนื่องจาก blockchain มีลักษณะแบบ peer-to-peer คุณจึงไม่สามารถโฮสต์ไฟล์ NFT และไฟล์ metadata บนบริการเว็บโฮสติ้งทั่วไปได้ `tokenURI` ของคุณจำเป็นต้องคงทน (หรือ "ไม่เปลี่ยนแปลง") และพกพาได้ข้ามแอปและมาร์เก็ตเพลสต่าง ๆ ให้นานที่สุดเท่าที่จะเป็นไปได้ ซึ่งอาจหมายถึงตลอดไป

นี่คือจุดที่ IPFS เข้ามามีบทบาท

## **เกี่ยวกับ IPFS**

[IPFS](https://ipfs.tech/) ย่อมาจาก InterPlanetary File System คือเครือข่ายไฟล์แบบกระจายศูนย์ที่ทำหน้าที่โฮสต์และแชร์ข้อมูลข้ามเครือข่ายที่กระจายตัว แพลตฟอร์ม NFT สามารถดึงข้อมูลจาก IPFS แทนที่จะพึ่งพาเซิร์ฟเวอร์เดียว และโปรโตคอล IPFS ทำให้รู้สึกเหมือนว่าไฟล์ที่โฮสต์ทั้งหมดอยู่ในเครื่องของคุณ

{% hint style="success" %}
**ฉันจำเป็นต้องเรียนรู้เกี่ยวกับ IPFS ตอนนี้เลยไหม?**

ขึ้นอยู่กับวิธีที่คุณเลือกในการ mint NFT:

* ใช้โค้ดโดยตรง (เช่น [viem](https://viem.sh/) หรือ [ethers](https://ethers.org/)):\
  **ใช่** คุณต้องมี `tokenURI` ที่ถูกต้อง (เช่น `ipfs://.../metadata.json`) ก่อน
* ผ่านแดชบอร์ด เช่น [thirdweb](https://thirdweb.com/):\
  **ไม่จำเป็น** การอัปโหลดไปยัง IPFS ถูกรวมไว้แล้ว คุณยังสามารถวาง `ipfs://...` ที่มีอยู่แล้วได้หากต้องการในพารามิเตอร์ NFT
* ใช้ Web3 SDK ส่วนใหญ่ (เช่น [Rarible's Multichain SDK](https://docs.rarible.org/reference/getting-started)):\
  **ใช่** SDK จะต้องการ URI เครื่องมือบางอย่างอาจช่วยในการอัปโหลดได้ แต่ไม่ใช่ทั้งหมด
  {% endhint %}

เว็บไซต์ IPFS มี [หน้าที่ครอบคลุมเกี่ยวกับแนวทางปฏิบัติที่ดีที่สุดในการจัดเก็บ NFT](https://docs.ipfs.tech/how-to/best-practices-for-nft-data/#types-of-ipfs-links-and-when-to-use-them)

## รายละเอียดการอัปโหลด NFT

เมื่ออัปโหลด NFT ของคุณ คุณต้องอัปโหลดสองรายการไปยัง Content Identifier (CID) ที่ IPFS สร้างให้คุณ:

* ตัวเนื้อหาเอง ซึ่ง IPFS จะส่งคืน URL ของ IPFS สำหรับไฟล์ที่โฮสต์
* ไฟล์ metadata ที่อ้างอิง CID ของไฟล์มีเดีย และต้องมี URL ของ IPFS สำหรับไฟล์นั้น

ทั้งสองรายการต้องอัปโหลดบน IPFS ภายใต้ CID เดียวกัน

ตามหลักการแล้ว เครื่องมือที่คุณใช้ควรจัดการสิ่งนี้ให้ เพื่อที่คุณจะไม่ต้องทำด้วยตนเองทั้งหมด

เพื่อให้เข้าใจ นี่คือตัวอย่างของไฟล์ `metadata.json` แบบขั้นต่ำ:

```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" 
    }] 
}
```

หากต้องการเรียนรู้เพิ่มเติมเกี่ยวกับโครงสร้าง metadata ของ NFT (เช่น ทำไมควรใช้ `image` สำหรับรูปภาพและ `animation_url` สำหรับวิดีโอ) เราแนะนำให้อ่านเอกสารนี้จาก OpenSea:

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

หมายเหตุ: *คุณไม่จำเป็นต้องเขียนไฟล์ metadata ตั้งแต่ต้น!*\
เครื่องมือที่คุณใช้ควรสามารถสร้างมันให้คุณได้

{% hint style="success" %}
คุณสามารถ [รัน IPFS node ของคุณเอง](https://docs.ipfs.tech/how-to/command-line-quick-start/) หรือจ่ายค่าบริการ IPFS เช่น [Pinata](https://pinata.cloud/) ซึ่งมีแผนบริการฟรีที่อาจเพียงพอสำหรับความต้องการของคุณ

ทำตาม [คู่มือเริ่มต้นใช้งานของ Pinata](https://docs.pinata.cloud/quickstart) เพื่อรับข้อมูลรับรอง API (ประกอบด้วย API key, API secret และ JWT token) และโดเมน Dedicated Gateway ของคุณ (เช่น `blue-genetic-quail-122.mypinata.cloud`)
{% endhint %}

เนื่องจากเอกสารนี้ไม่ได้มีจุดประสงค์เพื่ออธิบายทุกอย่างเกี่ยวกับ IPFS เราจึงแนะนำให้คุณเจาะลึกในหัวข้อนี้ผ่านการค้นหาออนไลน์ คุณสามารถเริ่มต้นด้วยบทความอธิบายของ Pinata:

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

... หรือบล็อกโพสต์นี้จาก thirdweb:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.chiliz.com/th/phatthana/sung-khuen/nft/host-ipfs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
