Storage via IPFS
// Using Web3Storage to make uploading to IPFS easier
const { Web3Storage, getFilesFromPath } = require('web3.storage');
// Create new client
const storageClient = new Web3Storage({ token: process.env.WEB3_STORAGE_KEY });async function task() {
const randomJoke = getRandomJoke();
// TODO sign data uploaded to IPFS to prove node uploaded it
const qodJSON = JSON.stringify(randomJoke);
const signedJSON = await namespace.signData(qodJSON);
fs.writeFileSync("qod.json", signedJSON);
if (storageClient) {
// Storing on IPFS through web3 storage as example
const file = await getFilesFromPath("./qod.json");
const cid = await storageClient.put(file);
console.log("CID of Uploaded Data: ", cid);
await namespace.checkSubmissionAndUpdateRound(cid);
} else {
console.error("No web3 storage API key provided");
}
}Last updated