# uploadToIPFS

## Description

The `uploadToIPFS` function uploads JSON data to the IPFS using the Pinata API and returns the IPFS hash of the uploaded data.

## Parameters

| Parameter            | Type   | Description                 |
| -------------------- | ------ | --------------------------- |
| `pinataApiKey`       | string | Pinata API key              |
| `pinataSecretApiKey` | string | Pinata API secret key       |
| `data`               | object | Data to be uploaded to IPFS |

## Response

| Property   | Type   | Description                    |
| ---------- | ------ | ------------------------------ |
| `ipfsHash` | string | IPFS hash of the uploaded data |

## Example Request and Response

### Prerequisites

Before making requests with Volary SDK, you must have it installed.

You can install Volary SDK using either **`npm`** or **`yarn`**. Use the following commands to install Volary SDK:

```jsx
npm install @nest25/storage-lib
OR
yarn add @nest25/storage-lib
```

### Request

Here is an example of how to make a `uploadToIPFS` request using the Volary SDK:

```javascript
// import Nest SDK library
const { StorageLibrary } = require('@nest25/storage-lib');
// create an instance of the storage library
const storageLibrary = new StorageLibrary();
// set the pinata api key and secret api key
const pinataApiKey = 'your-api-key';
const pinataSecretApiKey = 'your-secret-key';

async function main() {
  // upload data to IPFS
  const data = {
    name: 'test',
    age: 30,
  };
  // upload data to IPFS
  const result = await storageLibrary.uploadToIPFS(pinataApiKey, pinataSecretApiKey, data);
  // print the result
  console.log(result);
}
main();

```

### Response

```sh
 {
      IpfsHash: 'Qme6nVQjNfnrbFiZ5VFgbjvVL21xATkmH1gQWiQxtKJ6JY',
      PinSize: 32,
      Timestamp: '2023-03-09T08:36:16.052Z',
      isDuplicate: true
}
```

## Use Cases

* **NFT Marketplaces:** The function can be used by NFT marketplaces to upload NFT metadata to IPFS.
* **Decentralized Applications (DApps):** The function can be used by DApps to store data, such as user profiles or transaction records, on the IPFS network.
* **Digital Asset Management:** The function can be used by digital asset management systems to store and retrieve digital files, such as images or videos, on IPFS.


---

# 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.volary.io/sdks-guide/blockchain-sdks/storage-sdk/uploadtoipfs.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.
