Created
January 8, 2024 23:28
-
-
Save stevedylandev/11696bf39ccb0677a871af45eb4e5837 to your computer and use it in GitHub Desktop.
Pinning as fast as possible
This file contains hidden or 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
async function uploadJsonToPinata(jsonData, pinataApiKey) { | |
const axios = require("axios"); | |
const FormData = require("form-data"); | |
const url = "https://api.pinata.cloud/pinning/pinJSONToIPFS"; | |
try { | |
const data = JSON.stringify(jsonData); | |
const response = await axios.post(url, data, { | |
headers: { | |
"Content-Type": "application/json", | |
Authorization: `Bearer ${pinataApiKey}`, | |
}, | |
}); | |
return response.status; | |
} catch (error) { | |
console.error("Error uploading JSON to Pinata:", error); | |
throw error; | |
} | |
} | |
// function that adds a delay in ms | |
function delay(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
const main = async () => { | |
const pinataApiKey = "YOUR_JWT_HERE" | |
for (let i = 0; i < 100; i++) { | |
const jsonData = { | |
id: i, | |
}; | |
const pinataResponse = await uploadJsonToPinata(jsonData, pinataApiKey); | |
console.log(`Request ${i}: ${pinataResponse}`); | |
await delay(300); | |
} | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment