Last active
May 18, 2022 06:43
-
-
Save SocioDroid/35aca6498332e4cf9b329e22dc3b5d01 to your computer and use it in GitHub Desktop.
IPFS PINNING - Backend
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
const { create, urlSource } = require("ipfs-http-client"); | |
const ipfs = create({ url: "https://api.thegraph.com/ipfs/api/v0/" }); | |
console.log( | |
"~~~~~~~~~~~~ File pinning progress ~~~~~~~~~~~~" | |
); | |
console.log("\n\n"); | |
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay * 1000)); | |
async function pinToIPFS(metadataHash) { | |
try { | |
const file = await ipfs.add( | |
urlSource(`https://gateway.pinata.cloud/ipfs/${metadataHash}`) | |
); | |
console.log(`pinned file ---- ${file.cid}`); | |
} catch (error) { | |
console.log( | |
`pin file error ---- ${error.message}` | |
); | |
} | |
} | |
let uriArr = [ | |
{ | |
"tokenURI": "QmVfbKBM7XxqZMRFzRGPGkWT8oUFNYY1DeK5dcoTgLuV8H" | |
}, | |
{ | |
"tokenURI": "QmZUasDrDt7gKHUXZyN3FxXZEtCYbmCvMXMSw9grQ1yo6o" | |
}, | |
] | |
async function main(){ | |
for(var i = 0; i < uriArr.length; i++) | |
{ | |
pinToIPFS(uriArr[i].tokenURI); | |
await sleep(5); | |
} | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment