Blog Home
>
>
How can I get my IPFS CID?
How can I get my IPFS CID?

How can I get my IPFS CID?

4
Min read
How can I get my IPFS CID?
Getting your IPFS CID is a breeze with Pinata's user-friendly app or the developer-friendly API – a crucial step for seamless decentralized app development.

One of the most crucial things in Web3 is the CID; it acts as both the identifier and the address for content stored on IPFS. It’s used all over the place from NFTs to DeFi, tying together blockchain and off-chain storage to build a decentralized ecosystem. If you’re looking to get a CID for your own content, you first have to pin it to IPFS, which you can read in more detail here. In this post we’ll show you two ways you can easily get your IPFS CID.

The Pinata App

A simple and easy way to get a CID for your content is to use the Pinata App. This portal is made to be less technical and intuitive, making it seamless for anyone who wants to put a file on IPFS. To get started, first signup at app.pinata.cloud for a free account which will give you 1GB and 500 files worth of storage. After signing up, simply click on the “Add Files” button in the top right. From there pick your file, give it a name, and click upload; that easy!

Once the file has been uploaded, you’ll see the CID listed next to the name. Go ahead and click on it to copy the CID to your clipboard, and you’re ready to share your file across the blockchain 😎

The Pinata API

If you’re a developer and need to work with IPFS on a larger scale and more programmatically, then you’ll want to use the Pinata API. It’s an easy to use REST API with some great documentation you can check out, and uploading a file to get the CID will be a piece of cake. First you’ll want to go ahead and signup for a free account and create an API key. You can either give it admin permissions or just select the pinFileToIPFS if you want scoped permissions. Be sure to save the JWT which we’ll use as our authorization.

Now make a new project directory with your terminal and install some dependencies

mkdir pinata-upload && cd pinata-upload && npm install axios fs form-data

Next you can create a basic <span class="code-inline">Node.js</span> file with touch <span class="code-inline">index.js</span> and write the following code.

const axios = require('axios')
const FormData = require('form-data')
const fs = require('fs')
const JWT = 'PASTE_YOUR_PINATA_JWT'

const pinFileToIPFS = async () => {
    const formData = new FormData();
    const src = "path/to/file.png";
    
    const file = fs.createReadStream(src)
    formData.append('file', file)
    
    const pinataMetadata = JSON.stringify({
      name: 'API File',
    });
    formData.append('pinataMetadata', pinataMetadata);

    try{
      const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", formData, {
        maxBodyLength: "Infinity",
        headers: {
          'Content-Type': `multipart/form-data; boundary=${formData._boundary}`,
          'Authorization': `Bearer ${JWT}`
        }
      });
      console.log(res.data);
    } catch (error) {
      console.log(error);
    }
}

pinFileToIPFS()

Be sure to update the JWT constant at the top with your own API key (and of course use something like <span class="code-inline">dotenv</span> when putting anything in production or online), and also change the file path for <span class="code-inline">src</span>. After that you should be able to go ahead and run <span class="code-inline">npm run index.js</span> and you should see the following in your terminal.

{
  IpfsHash: "QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng",
  PinSize: 32942,
  Timestamp: "2023-09-08T19:17:41.533Z"
}

You can see that the API will return to us the <span class="code-inline">IpfsHash</span> or in other words, our CID! You could also extract this as an object for simpler handling like so.

const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS",
  formData,
  {
    maxBodyLength: "Infinity",
    headers: {
      "Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
      Authorization: `Bearer ${JWT}`,
    },
  }
);
const { IpfsHash } = res.data;
console.log("Your IPFS CID is:", IpfsHash);

And this would give you the following

Your IPFS CID is: QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng

From there you can start using the CID wherever you need it in your decentralized application!

We hope you found this helpful when it comes to getting your IPFS CID, and of course if you need any help we’re here to talk. Reach out to us through the chat on our website or email us, and we can’t wait to see what you build.

Happy pinning!

4
MIN READ

H1 - THE RICH TEXT
EXAMPLE STARTS HERE

H2 - Enabling Widespread Adoption for Music NFTs

paragraph — The first thing the music industry needs is more exposure. For artists, listeners and yeah, the labels. Even with the use cases mentioned above, the majority of the music industry still sees NFTs as a novelty rather than a legitimate way to run a business. We see a future where the experience is built and monetized on the blockchain, with labels taking part of the experience, as well.

Second, there needs to be a big jump in user experience. Listeners know what to expect with Spotify and Apple Music: a smooth, intuitive experience that lets them listen to Lil Nas X with just a few clicks. Web3 platforms aren’t quite there. Music NFTs and related premium content require extra steps that most people don’t yet have an appetite for.

H3 - How Could Music NFTs Save Artists?

paragraph — Musician Daniel Allan spent months building a relationship with the NFT community and raised 50 ETH to fund his new album, Overstimulated. Companies like Audius and artists like Vérité's, who raised $90,000 in an NFT launch, are at the forefront of exploring new ways to get paid. Avenged Sevenfold launched an NFT collection called "Deathbats Club" with 10,000 items that grants holders access to benefits such as meet and greets at shows, lifetime free tickets, limited edition merchandise, and more.

Photo of ETHDenver 2022 with Pinata employees
This can also be styled!! Image caption.

H4 - Static and dynamic content editing

A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!

H5 — How to customize formatting for each rich text

Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.

LINK — This is how a link looks like. Please provide normal & hover state (if different than this)

  • This will be bullet points
  • Numbered list is the same but with numbers
  • It has a margin-left applied
  1. Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.
  2. Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.
  3. Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.
QUOTE — Everyone is obsessed with making money and seeking alpha, which does a disservice to what [NFTs] can actually do. We have been instructing many bands that NFTs are a ticket for access to an exclusive club.” - M. Shadows, Avenged Sevenfold’s lead singer.