LESSON 14: Type error deploying - Cannot read properties of undefined #2565
-
Terminal output: Local network detected! Deploying mocks to local network...
deploying "vrfCoordinatorV2Mock" (tx: 0x3a4e4c4afe3ffa732c329b1cdbba306c608c43d8276dcddca66051fe11087996)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 53364 gas
deploying "MockV3Aggregator" (tx: 0x685426a88aac3c1caee832c6ec76bc61cd8d81f053edcec2ba48be25f7cc6b76)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 697014 gas
Mocks deployer!
______________________________________________________________
You are deploying to a local network, you need a local network running to interact
Plz run `yarn hardhat console --network localhost` to interact with deployed smart contracts!
______________________________________________________________
______________________________________________________
deploying "BasicNFT" (tx: 0x63493984b8a3f64eff58eeac27cf53841c3ab9b3bb2bb9ae769cb834608ae66b)...: deployed at 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 with 2014805 gas
______________________________________________________
[ 'pug.png', 'shiba-inu.png', 'st-bernard.png' ]
Uploading to Pinata!
Working on 0...
Working on 1...
Working on 2...
Uploading pug...
Uploading shiba-inu...
Uploading st-bernard...
Token URIs Uploaded! They are:
[
'ipfs://QmaVkBn2tKmjbhphU7eyztbvSQU5EXDdqRyXZtRhSGgJGo',
'ipfs://QmYQC5aGZu2PTH8XzbJrbDnvhj3gVs7ya33H9mqUNvST3d',
'ipfs://QmZYmH5iDbD6v3U2ixoVAjioSzvWJszDzYdbeCLquGSpVm'
]
An unexpected error occurred:
Error: ERROR processing /home/ionmind/hh-fcc/hardhat-nft-fcc/deploy/02-deploy-random-ipfs-nft.js:
TypeError: Cannot read properties of undefined (reading 'args') ============================================================================= Code block triggering the error
====================================================================================== Deploy script const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
const { storeImages, storeTokenUriMetadata } = require("../utils/uploadToPinata")
const imagesLocation = "./images/randomNFT/"
let tokenUris = []
const metadataTemplate = {
name: "",
description: "",
image: "",
attributes: [
{
trait_type: "Cuteness",
value: 100,
},
],
}
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let tokenUris
if (process.env.UPLOAD_TO_PINATA == "true") {
tokenUris = await handleTokenUris()
}
let vrfCoordinatorV2Address, subscriptionId
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.events[0].args.subId
} else {
vrfCoordinatorV2Address = networkConfig[chainId].vrfCoordinatorV2
subscriptionId = networkConfig[chainId].subscriptionId
}
log("______________________________________________________")
const args = [
vrfCoordinatorV2Address,
subscriptionId,
networkConfig[chainId].gasLane,
networkConfig[chainId].callbackGasLimit,
networkConfig[chainId].mintFee,
tokenUris,
]
const randomIpfsNft = await deploy("RandomIpfsNFT", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
log("_________________________________________________________")
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(randomIpfsNft.address, args)
}
}
async function handleTokenUris() {
tokenUris = []
const { responses: imageUploadResponses, files } = await storeImages(imagesLocation)
for (imageUploadResponses.Index in imageUploadResponses) {
//create metadata
//upload metadata
let tokenUriMetadata = { ...metadataTemplate }
tokenUriMetadata.name = files[imageUploadResponses.Index].replace(".png", "")
tokenUriMetadata.description = `An adorable ${tokenUriMetadata.name} pup!`
tokenUriMetadata.image = `ipfs://${imageUploadResponses[imageUploadResponses.Index].IpfsHash}`
console.log(`Uploading ${tokenUriMetadata.name}...`)
const metadataUploadResponse = await storeTokenUriMetadata(tokenUriMetadata)
tokenUris.push(`ipfs://${metadataUploadResponse.IpfsHash}`)
}
console.log("Token URIs Uploaded! They are:")
console.log(tokenUris)
return tokenUris
}
module.exports.tags = ["all", "randomIpfsNFT", "main"] ====================================================================================== Upload to pinata script const pinataSDK = require("@pinata/sdk")
const path = require("path")
const fs = require("fs")
require("dotenv").config()
const pinataApiKey = process.env.PINATA_API_KEY
const pinataApiSecret = process.env.PINATA_API_SECRET
const pinata = pinataSDK(pinataApiKey, pinataApiSecret)
async function storeImages(imagesFilePath) {
const fullImagesPath = path.resolve(imagesFilePath) //full output of the path
const files = fs.readdirSync(fullImagesPath) //read entire directory & get files path
console.log(files)
let responses = []
console.log("Uploading to Pinata!")
for (fileIndex in files) {
console.log(`Working on ${fileIndex}...`)
const readableStreamForFile = fs.createReadStream(`${fullImagesPath}/${files[fileIndex]}`)
try {
const response = await pinata.pinFileToIPFS(readableStreamForFile)
responses.push(response)
} catch (error){
console.log(error)
}
}
return { responses, files }
}
async function storeTokenUriMetadata(metadata) {
try {
const response = await pinata.pinJSONToIPFS(metadata)
return response
} catch (error) {
console.log(error)
}
return null
}
module.exports = { storeImages, storeTokenUriMetadata } ====================================================================================== I have literally tried everything under the sun but still unable to pinpoint the issue. Code was deploying and compiling perfectly before we unquoted the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
@DorianDaSilva : I'm listing the corrections below:
Your
|
Beta Was this translation helpful? Give feedback.
-
@DorianDaSilva : Do the following changes in your
In your "deploy script" change the order of your args "and" remove the coma from the last argument:From this :
To this : Just Copy & Paste this one exactly!
Hopefully, It will resolve your issue! |
Beta Was this translation helpful? Give feedback.
-
If this is not resolved yet, push to GitHub and I will look into it |
Beta Was this translation helpful? Give feedback.
-
Modified the script using inheritance instead of hard coding Opensea contracts. Seems I was missing some dependencies from open sea to be able to make it work 100%...Thank you for the help guys, I appreciate it a lot! |
Beta Was this translation helpful? Give feedback.
Modified the script using inheritance instead of hard coding Opensea contracts. Seems I was missing some dependencies from open sea to be able to make it work 100%...Thank you for the help guys, I appreciate it a lot!