Error: ERROR processing skip func of /deploy/02-deploy-random-ipfs-nft.js: TypeError: Cannot call a class as a function
faresdevweb opened this issue · comments
Hey! I'm following Patrick's courses on full stack web3 developpements and I'm running an Issue whit the deploy scripts of randomIpfsNFT
I just added the uploadToPinata.js function into utils and wrote the code to upload to Pinata, seems like the function is working correctly but it broke the files 02-deploy-random-ipfs-nft.js here is the code
const { network, ethers } = require("hardhat");
const {
developmentChains,
networkConfig,
} = require("../helper-hardhat-config");
const { verify } = require("../utils/verify");
const { storeImages } = require("../utils/uploadToPinata");
const imagesLocation = "./images/randomNFT";
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
let tokenUris;
// GET IPFS hashes of our images
// 1. with our own IPFS node
// 2. with Pinata
if (process.env.UPLOAD_TO_PINATA === "true") {
tokenUris = await handleTokensUris();
}
// 3. NFT.storage
let vrfCoordinatorV2Address, subscriptionId;
log("----------------------------------------------------");
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract(
"VRFCoordinatorV2Mock"
);
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address;
const tx = await vrfCoordinatorV2Mock.createSubscription();
const txReceipt = await tx.wait(1);
subscriptionId = txReceipt.logs[0].args.subId;
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"];
subscriptionId = networkConfig[chainId]["subscriptionId"];
}
log("----------------------------------------------------");
await storeImages(imagesLocation);
// const args = [
// vrfCoordinatorV2Address,
// subscriptionId,
// networkConfig[chainId].gasLane,
// networkConfig[chainId].mintFee,
// networkConfig[chainId].callbackGasLimit,
// // TokenURI,
// ];
};
async function handleTokensUris() {
tokenUris = [];
return tokenUris;
}
module.exports.tags = ["all", "randomipfs", "main"];
while executing the command "yarn hardhat deploy --tags randomipfs,mocks, I have the following output error
Error: ERROR processing skip func of /hh-fcc/hardhat-nft-fcc/deploy/02-deploy-random-ipfs-nft.js: TypeError: Cannot call a class as a function
I'm not finding anything to resolve this on StackOverFlow or on this repo
So I tried something, the error occurs after adding this lines ->
const { storeImages } = require("../utils/uploadToPinata");
so after removing it from the code and comment the await storeImages(imagesLocation)
in my deploy scripts it works correctly
so the issues is in this file
utils/uploadToPinata.js ->
const pinataSDK = require("@pinata/sdk");
const path = require("path");
const fs = require("fs");
require("dotenv").config();
const pinataApiKey = process.env.PINATA_API_KEY;
const pinata_secret_api_key = process.env.PINATA_API_SECRET;
const pinata = pinataSDK(pinataApiKey, pinata_secret_api_key);
async function storeImages(imagesFilePath) {
const fullImagesPath = path.resolve(imagesFilePath);
const files = fs.readdirSync(fullImagesPath);
console.log("Uploading images to Pinata...");
let responses = [];
console.log("Uploading images to IPFS...");
for (fileIndex in files) {
const readableStreamForFile = fs.createReadStream(
`${fullImagesPath}/${files[fileIndex]}`
);
try {
const response = await pinata.pinFileToIPFS(readableStreamForFile);
responses.push(response);
} catch (error) {
console.log("ERROR IN CATCH FUNCTION STORE IMAGE", error);
}
}
}
module.exports = { storeImages };
try doing this -->
for (const fileIndex in files) {
const readableStreamForFile = fs.createReadStream(${fullImagesPath}/${files[fileIndex]}
)
const options = {
pinataMetadata:{
name:files[fileIndex]
},
}
try {
await pinata.pinFileToIPFS(readableStreamForFile, options)
.then((result)=>{
responses.push(result)})
.catch((err)=>{
console.log(err)
})
} catch (e) {
console.error(e)
}
}
if you have still problem then try doing debug by adding console.log between the codes then you can get where in your code has problem
const pinata = pinataSDK(pinataApiKey, pinata_secret_api_key);
In your utils/uploadToPinata.js
on line 7 -> 'new' is missing.
const pinata = new pinataSDK(pinataApiKey, pinata_secret_api_key);
Can you try this and see if it works?
I also have this issue, and I haven't been able to fix it