-
Notifications
You must be signed in to change notification settings - Fork 7
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
13 changed files
with
118 additions
and
88 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
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
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
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
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
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 |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import { create } from "ipfs-http-client"; | ||
import { getEnv } from "./env"; | ||
|
||
const IPFS_ENDPOINT = getEnv("DEPLOYMENT_IPFS_ENDPOINT", true) ?? ""; | ||
const IPFS_API_KEY = getEnv("DEPLOYMENT_IPFS_API_KEY", true) || ""; | ||
const PINATA_JWT = getEnv("DEPLOYMENT_PINATA_JWT", true) || ""; | ||
const APP_NAME = getEnv("DEPLOYMENT_APP_NAME", true) || ""; | ||
|
||
export const deploymentIpfsClient = create({ | ||
url: IPFS_ENDPOINT, | ||
headers: { "X-API-KEY": IPFS_API_KEY, Accept: "application/json" }, | ||
}); | ||
const UPLOAD_FILE_NAME = APP_NAME.toLowerCase().trim().replaceAll(" ", "-") + ".json"; | ||
|
||
export async function uploadToPinata(strBody: string) { | ||
const blob = new Blob([strBody], { type: "text/plain" }); | ||
const file = new File([blob], UPLOAD_FILE_NAME); | ||
const data = new FormData(); | ||
data.append("file", file); | ||
data.append("pinataMetadata", JSON.stringify({ name: UPLOAD_FILE_NAME })); | ||
data.append("pinataOptions", JSON.stringify({ cidVersion: 1 })); | ||
|
||
const res = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${PINATA_JWT}`, | ||
}, | ||
body: data, | ||
}); | ||
|
||
const resData = await res.json(); | ||
|
||
if (resData.error) throw new Error("Request failed: " + resData.error); | ||
else if (!resData.IpfsHash) throw new Error("Could not pin the metadata"); | ||
return "ipfs://" + resData.IpfsHash; | ||
} |
Oops, something went wrong.