This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profile] Upload metada doc to IPFS (#1393)
# Summary This PR closes #942 A function was added in order to receive the metadata doc and upload this to IPFS (and pinning it using Pinata) An example of a test metadata doc pinned with Pinata: https://gateway.pinata.cloud/ipfs/QmQVCKwriSzFpz5Ybjp3iumJ9HpMq7bS9aReYvxDBactew # To Test It can be tested by calling `uploadMetadataDocToIpfs` and passing a metadata doc as a parameter (We could use `generateReferralMetadataDoc` with a test address). - For testing purposes, I use my own Pinata account credentials. We'll need to create a corporate account for production. - We need to add `REACT_APP_PINATA_API_KEY` and `REACT_APP_PINATA_SECRET_API_KEY` enviroment variables to the `.env` file. _Node version was updated in order to use `ipfs-core` and `@sdk/pinata` dependencies_
- Loading branch information
Showing
5 changed files
with
484 additions
and
13 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,17 @@ | ||
import safeStringify from 'fast-safe-stringify' | ||
import pinataSDK, { PinataPinByHashResponse } from '@pinata/sdk' | ||
import { IPFS_URI, PINATA_API_KEY, PINATA_SECRET_API_KEY } from 'constants/ipfs' | ||
|
||
const pinata = pinataSDK(PINATA_API_KEY, PINATA_SECRET_API_KEY) | ||
|
||
export async function uploadTextFileToIpfs(file: any): Promise<string> { | ||
const { create } = await import('ipfs-http-client') | ||
const client = create({ url: IPFS_URI }) | ||
const doc = safeStringify.stableStringify(file) | ||
const { cid } = await client.add(doc) | ||
return cid.toString() | ||
} | ||
|
||
export async function pinByHash(hash: string): Promise<PinataPinByHashResponse> { | ||
return pinata.pinByHash(hash) | ||
} |
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,3 @@ | ||
export const PINATA_API_KEY = process.env.REACT_APP_PINATA_API_KEY as string | ||
export const PINATA_SECRET_API_KEY = process.env.REACT_APP_PINATA_SECRET_API_KEY as string | ||
export const IPFS_URI = process.env.REACT_APP_IPFS_URI || 'https://ipfs.infura.io:5001/api/v0' |
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
Oops, something went wrong.