# IPFS Cache Data Upload and Synchronization Guide

This guide outlines the steps required to upload and synchronize data in the IPFS cache, ensuring compatibility with the frontend.

***

### **Uploading Files to IPFS**

You can use any uploader or service to upload files and JSON metadata to IPFS.

***

### **Supported File Formats**

Currently, the frontend supports the following avatar file formats:

* `.gif`
* `.jpg`

Ensure the uploaded file meets these format requirements.

***

### **CID Format**

After uploading a file, the service will return a **CID (Content Identifier)**. IPFS supports multiple CID formats. Our frontend supports **CID v1 (base32)**, which looks like this:

`bafybeigxhwjaljyquoltsz7o6qq24npbk2diz2s43wsxl6dqagne3qvnsq`

Avoid using the older **CID v0** format, which appears as:

`QmcprpP6Sc3LY4x4BDbGNo1k5e3CwcDRCNmaZ9kX6GLnAo`

For more details on CIDs, refer to:

* [IPFS Content Addressing](https://docs.ipfs.tech/concepts/content-addressing/)
* [CID Specification](https://cid.ipfs.tech/)

***

### **Creating Metadata JSON**

Once the CID is obtained and formatted to **CID v1 (base32)**, you need to create a JSON structure to store the metadata required by the frontend.

The metadata format is similar to OpenSea standards:

[OpenSea Metadata Standards](https://docs.opensea.io/docs/metadata-standards)

Example JSON (refer to this sample when creating own json):

[Sample JSON](https://ipfs-cache.dexe.io/bafybeiapxtj7d65qwu6byb3twjt4fpdqmkw4ilagsqc3zdgpzplxzbtunu.json)

**Differences from OpenSea Format**:

* `image`: The CID of the uploaded image in **CID v1 (base32)** format + the file extension (e.g., `.jpg` or `.gif`).
* `description`: Should not contain special characters and must be limited to 256 characters.

***

### **Synchronizing Files with IPFS Cache**

After adding the image CID to the JSON and uploading the JSON to IPFS, synchronize both files (image + JSON) with the IPFS cache.

**API Request for Synchronization**

**URL:** `https://api.dexe.io/integrations/ipfs-cache-svc/public/pool-info`

**Method:** POST

**Headers:**

```json
{
  https://maps.app.goo.gl/MRBNG11Hs66srAEP6"Content-Type": "application/json"
}
```

**Body:**

```json
{
  "data": {
    "attributes": {
      "link": "your_cid_here"
    }
  }
}
```

***

### **Accessing Content**

Once synchronized, the content will be accessible and viewable on the frontend. You can verify it using the following GET requests:

#### **JSON Metadata**:

`https://ipfs-cache.dexe.io/<json_cid>.json`

*Example:*

`https://ipfs-cache.dexe.io/bafybeiapxtj7d65qwu6byb3twjt4fpdqmkw4ilagsqc3zdgpzplxzbtunu.json`

#### **Image File**:

`https://ipfs-cache.dexe.io/<image_cid>.<extension>`

*Example:*

`https://ipfs-cache.dexe.io/bafybeidfdzuvo7ostazu3sw65mmmf46vo6h3fa5qxeqmo56gwqsndvduo4.jpg`

***

By following this guide, your data will be correctly uploaded, synchronized, and ready for frontend integration.

## CID format Conversion Guide (node js)

```
import { CID } from 'multiformats/cid' 
import { base32 } from 'multiformats/bases/base32'
async function convertCID(oldCID) { 
    try { 
        // Parse the old CID 
        const parsed = CID.parse(oldCID)

        // Create new CIDv1 in base32
        const newCID = parsed.toV1()

        // Convert to base32 string
        return newCID.toString(base32)
    } catch (error) {
        console.error('Error converting CID:', error)
        throw error
    }
}
```

```
// Usage example
async function main() {
    const oldCID = 'QmdfLnJ22TFRPdvqKMirjxgVVRassP9Si8YqpK6nbBcZDw'
    try {
        const newCID = await convertCID(oldCID)
        console.log('Old CID:', oldCID)
        console.log('New CIDv1 (Base32):', newCID)
    } catch (error) {
        console.error('An error occurred:', error)
    } 
}
main()
```


---

# Agent Instructions: 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:

```
GET https://docs.gra.fun/tech-guide/ipfs-cache-data-upload-and-synchronization-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
