NFT lesson No pinataSecretApiKey provided! #1474
Answered
by
alymurtazamemon
AlexK020908
asked this question in
Q&A
-
//we would want to pin our file and json files(file = picture, jsonfile --> meta data)
const pinataSDK = require("@pinata/sdk")
const fs = require("fs")
const path = require("path")
require("dotenv").config()
const pinataApiKey = process.env.PINATA_API || ""
const pinataSecretApiKey = process.env.PINATA_API_SECRET || ""
const pinata = pinataSDK(pinataApiKey, pinataSecretApiKey)
async function storeImages(imagesFilePath) {
const fullImagesPath = path.resolve(imagesFilePath) //gets the full path
//like /home/alexk/wsl/ubuntu ..... you get the idea
console.log(fullImagesPath)
const files = fs.readdirSync(fullImagesPath) //read everthing in that dir...
console.log(files)
let reponses = []
for (fileIndex in files) {
//for each of the file
const readableStream = fs.createReadStream(`${fullImagesPath}/${files[fileIndex]}`)
//we stream all the data in the images, images are full of bytes and data
try {
const reponses = await pinata.pinFileToIPFS(readableStream)
reponses.push(reponses)
} catch (error) {
console.error(error)
}
}
return { reponses, files }
}
module.exports = { storeImages } When I am trying to upload files up to pinata with this script (also included in my deploy script), the following error happens:
I have clearly included the secret key but the error presists, any help is appreciated, below is my deploy script if one considers it helpful const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
const { storeImages } = require("../utils/uploadToPinata")
module.exports = async function ({ deployments, getNamedAccounts }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainID = network.config.chainId
let randomNFT
let VRfaddress
let subID
const args = []
const mintFee = await ethers.utils.parseEther("0.2")
let tokenuris
if (chainID == 31337) {
log("local network detected, deploying to local network")
const mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
VRfaddress = mock.address
//create subscrioption
const tx = await mock.createSubscription()
const receipt = await tx.wait(1)
subID = receipt.events[0].args.subId //it emits an event
//fund it ...
} else {
VRfaddress = networkConfig[chainID]["vrfCoordinator"]
subID = networkConfig[chainID]["subscriptionID"]
}
log("--------------------------------")
if (process.env.UPLOAD_TO_PINDATA == "true") {
tokenuris = await handleTokenUris() //this function uploads our code to pinaata
}
//for the images, we need the ipfs hashes programattically
/*
1. with our own IPFS node (manually) https://docs.ipfs.io
2. use pinata https://www.pinata.cloud
3. NFT.storage https://www.nft.storage an entire network pinning your data
*/
await storeImages("./images/randomnft")
console.log("store images")
// const arguments = [
// networkConfig[chainID]["vrfCoordinator"],
// subID,
// networkConfig[chainID]["callbackGasLimit"],
// networkConfig[chainID]["gasLane"],
// /** the files in string format pointing to IPFS , */
// mintFee,
// ]
// randomNFT = await deploy("basicNFT", {
// from: deploy,
// log: true,
// args: args,
// waitConfirmations: network.config.blockConfirmations || 1,
// })
// if (chainId != 31337 && process.env.ETH_API_KEY) {
// verify(randomNFT.address, args)
// }
}
async function handleTokenUris() {
tokenUris = []
//store image in ipfs
//store metadata in ipfs
return tokenuris
}
module.exports.tags = ["all", "randomipfs"] here is a link to my repo https://github.com/AlexK020908/hardhdat-nft |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Aug 3, 2022
Replies: 1 comment 11 replies
-
@AlexK020908 try to add like this |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
alymurtazamemon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AlexK020908 try to add like this
const pinata = pinataSDK(process.env.PINATA_API, process.env.PINATA_API_SECRET);
and make sure toconsole.log()
API key and secret before this