Node.js
Setup a Node.js Project
To start you can go to your terminal and put in the following code
Then install the Pinata SDK as well as dotenv
In the root of the directory make a .env
file where we’re pull 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
.
Now we’ll make two files, index.js
and hello-world.txt
.
Inside the hello-world.txt
you can put whatever you’d like such as Hello World!
.
Upload a File to Pinata
Once we have our initial project setup we can put the following code into our index.js
file.
You can run this by using node index.js
in the terminal. After uploading a file you should get a response that looks like this
Fetch the File through a Gateway
With the cid
you can view the file or fetch the data using your Gateway. Lets make a new file called fetch.js
and put in the following code.