Created
May 18, 2022 06:48
-
-
Save SocioDroid/748c37cdfb120003e4400315e5a8fe39 to your computer and use it in GitHub Desktop.
Snippet for IPFS pinning
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
import { create, urlSource } from "ipfs-http-client"; | |
const fromIpfsURL = "https://gateway.pinata.cloud/ipfs"; | |
const toIpfsURL = "https://api.thegraph.com/ipfs/api/v0/"; | |
const ipfs = create({ url: toIpfsURL }); | |
console.log( | |
"~~~~~~~~~~~~ File pinning progress ~~~~~~~~~~~~" | |
); | |
console.log("\n\n"); | |
async function pinToIPFS(metadataHash) { | |
try { | |
const file = await ipfs.add( | |
urlSource(`${fromIpfsURL}/${metadataHash}`) | |
); | |
console.log(`pinned file ---- ${file.cid}`); | |
} catch (error) { | |
console.log( | |
`pin file error ---- ${error.message}` | |
); | |
} | |
} | |
let ipfsHash = "QmVhWEoKsycEnEJWq4aHwJVNv9oxdkjv19cGp98yc9r2FJ"; | |
pinToIPFS(ipfsHash); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment