-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinata.config.js
33 lines (31 loc) · 891 Bytes
/
pinata.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import axios from "axios";
const pinataConfig = {
API_KEY: process.env.NEXT_PUBLIC_PINATA_API_KEY,
API_SECRET: process.env.NEXT_PUBLIC_PINATA_API_SECRET,
JWT: process.env.NEXT_PUBLIC_PINATA_JWT
};
export default pinataConfig;
export const pinJSONToIPFS = async (fileObj) => {
const url = `https://api.pinata.cloud/pinning/pinFileToIPFS`;
//making axios POST request to Pinata ⬇️
const res = await axios
.post(url, fileObj, {
headers: {
pinata_api_key: pinataConfig.API_KEY,
pinata_secret_api_key: pinataConfig.API_SECRET,
}
})
.then(function(response) {
return {
success: true,
pinataUrl: "https://gateway.pinata.cloud/ipfs/" + response.data.IpfsHash
};
})
.catch(function(error) {
console.log(error)
return {
success: false,
message: error.message,
}
});
};