⛏️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 Nest SDK, you must have it installed.

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

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 Nest SDK:

// 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

 {
      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.

Last updated