Skip to content

Instantly share code, notes, and snippets.

@SocioDroid
Created May 18, 2022 06:48
Show Gist options
  • Save SocioDroid/748c37cdfb120003e4400315e5a8fe39 to your computer and use it in GitHub Desktop.
Save SocioDroid/748c37cdfb120003e4400315e5a8fe39 to your computer and use it in GitHub Desktop.
Snippet for IPFS pinning
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