React
Start up React Project
Run the command below to make a new React project:
Give the project a name and select the React framework. Then cd
into the project and install pinata
.
After making the project, create a .env.local
file in the root of the project and put in the following variables:
Use the JWT
from the API key creation in the previous step as well as the Gateway Domain
. The format of the Gateway domain should be mydomain.mypinata.cloud
.
Setup Pinata
Create a directory called utils
in the src
folder of the project and then make a file called config.ts
inside of it. In that file we’ll export an instance of the IPFS SDK that we can use throughout the rest of the app.
Create Upload Form
Next we’ll want to make an upload form on the client side that will allow someone to select a file and upload it.
In the src/App.tsx
file take out the boiler plate code and use the following. Switch between tabs if you want to see how you would handle folder uploads.
Pull Content from IPFS
After we have uploaded the file and get the CID back we can create a signed URL for the file to either download it or render it in our app. For this example we will assume the file is an image, but Pinata supports any kind of file type.
We can do this by adding the following code to our App.tsx
file.