When we upload content to Pinata, the immediate desire is typically to view it on the InterPlanetary File System (IPFS) network. However, there’s a hurdle: IPFS operates as a distinct protocol, much like HTTP for conventional websites. A gateway is necessary to connect IPFS with HTTP to access the content. IPFS gateways serve this purpose by facilitating seamless interaction between the two protocols.
Setting up Pinata as an IPFS gateway is straightforward. Pinata offers a user-friendly interface and a free plan that allows us to quickly get started with IPFS.
The process to set up Pinata as an IPFS gateway is simple. Follow the steps below to set Pinata as an IPFS gateway:
Create a Pinata account:
Visit the Pinata website and sign up for a Pinata account.
Once registered, log in to your Pinata account.
Get your API key and secret:
After logging in, navigate to the “API Keys” section in your Pinata account.
Create a new API key and secret. These credentials will be used to interact with the Pinata IPFS API.
Once you've acquired the API key and secret, copy your JSON Web Token (JWT) as well.
Install IPFS:
Before using Pinata, you must install IPFS on your local machine.
Feel free to check the official documentation of IPFS to install it.
Initialize IPFS:
Open a terminal and run the following command to initialize your local IPFS node:
ipfs init
Configure IPFS to use Pinata as a gateway:
Run the following command to configure your local IPFS node to use Pinata as a gateway:
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
Start IPFS daemon:
Start the IPFS daemon to run your local IPFS node with the following command:
ipfs daemon
Upload content to Pinata IPFS network:
Use the Pinata API to upload content to the IPFS network via the Pinata gateway. Replace YOUR_API_KEY
and YOUR_API_SECRET
with your actual Pinata API key and secret.
curl -H "Content-Type: application/json" \-H "pinata_api_key: YOUR_API_KEY" \-H "pinata_secret_api_key: YOUR_API_SECRET" \--data '{"pinataMetadata": {"name": "YourFile.txt"}}' \-X POST \https://api.pinata.cloud/pinning/pinFileToIPFS \--data-binary @YourFile.txt
This command uploads the content of YourFile.txt
to the IPFS network using Pinata.
The –data-binary
is a flag used with the curl
command to mark the type of data sent.
Access your content via Pinata IPFS gateway:
After uploading, you can access your content through the Pinata IPFS gateway by constructing a URL. Replace YOUR_CID
with the actual CID returned when you uploaded the file.
https://gateway.pinata.cloud/ipfs/YOUR_CID
For example:
https://gateway.pinata.cloud/ipfs/QmZ9iRruq9aa1ZGvYeeTmMyty9bXd1PRVgWuZCAsUNY1Q4
This URL serves as a direct link to your content on the IPFS network through Pinata.
That’s it! You've successfully set up Pinata as your IPFS gateway, configured your local IPFS node, and uploaded content to the IPFS network. An IPFS gateway is needed to store and retrieve the NFT images and metadata into the IPFS network. You can now use Pinata as a reliable and accessible gateway for sharing and retrieving IPFS content.
Free Resources