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
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.
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.
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.
And this would give you the following
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.
September 13, 2023
Ready to shape the future?
Explore our plans