-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export async function uploadToPinata(source: string) { | ||
const PINATA_KEY = process.env.PINATA_KEY; | ||
if (!PINATA_KEY) throw new Error('PINATA_KEY env must be set'); | ||
const PINATA_SECRET = process.env.PINATA_SECRET; | ||
if (!PINATA_SECRET) throw new Error('PINATA_SECRET env must be set'); | ||
const data = new FormData(); | ||
data.append('file', new Blob([source])); | ||
const res = await fetch('https://api.pinata.cloud/pinning/pinFileToIPFS', { | ||
method: 'POST', | ||
body: data, | ||
headers: { | ||
pinata_api_key: PINATA_KEY, | ||
pinata_secret_api_key: PINATA_SECRET, | ||
}, | ||
}); | ||
|
||
if (!res.ok) { | ||
throw Error(await res.text()); | ||
} | ||
|
||
const result = await res.json(); | ||
|
||
if (result.error) throw { message: result.error }; | ||
return result; | ||
} | ||
|
||
export async function uploadToTheGraph(source: string) { | ||
const data = new FormData(); | ||
data.append('file', new Blob([source])); | ||
const res = await fetch('https://api.thegraph.com/ipfs/api/v0/add', { | ||
method: 'POST', | ||
body: data, | ||
}); | ||
return await res.json(); | ||
} |