PatrickAlphaC / all-on-chain-generated-nft

A repo for generating random NFTs with metadata 100% on chain!
MIT License
356 stars 150 forks source link

TypeError: Cannot read property 'length' of undefined #6

Closed toufic0710 closed 3 years ago

toufic0710 commented 3 years ago

Hi patrick,

I am following your tutorial and it is very instrictive. However, I face some troubles when I try to deploy the code to rinkeby (when I try to deploy it on a local network I do not have this issue) , I got the error "Cannot read property 'length' of undefined" and I am not able to find from where it comes from.

Here is the error : image

Here is my hardhat.config.js file


require("@nomiclabs/hardhat-waffle")
 require("@nomiclabs/hardhat-ethers")
 require("@nomiclabs/hardhat-truffle5")
 require("@nomiclabs/hardhat-etherscan")
 require("hardhat-deploy")
 require('dotenv').config()
 //const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL  
 const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL 
 //const KOVAN_RPC_URL = process.env.KOVAN_RPC_URL 
 //const MNEMONIC = process.env.MNEMONIC 
 const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
 // optional
 const PRIVATE_KEY = process.env.PRIVATE_KEY 
 module.exports = {
     defaultNetwork: "hardhat",
     networks: {
         hardhat: {
             // // If you want to do some forking, uncomment this
             // forking: {
             //   url: MAINNET_RPC_URL
             // }
         },
         localhost: {
         }, 
         rinkeby: {
             url: RINKEBY_RPC_URL,
             accounts: [PRIVATE_KEY],
             //accounts: {
             //    mnemonic: MNEMONIC,
             //},
             saveDeployments: true,
         },
     },
     etherscan: {
         // Your API key for Etherscan
         // Obtain one at https://etherscan.io/
         apiKey: ETHERSCAN_API_KEY
     },
     namedAccounts: {
         deployer: {
             default: 2, // here this will by default take the first account as deployer
             1: 0 // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
         },
         feeCollector: {
             default: 1
         }
     },
     solidity: {
         compilers: [
             {
                 version: "0.8.0"
             }
         ]
     },
     mocha: {
         timeout: 100000
     }
 }

Here is my 01_deploy_svgnft.js file:


let { networkConfig } = require('/mnt/c/Users/.../all-on-chain-generated-nft/all-on-chain-test/helper-hardhat-config')
const fs = require('fs')

module.exports = async ({
    getNamedAccounts,
    deployments,
    getChainId
}) => {

    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = await getChainId()

    log("----------------------------------------------------")
    const SVGNFT = await deploy('SVGNFT', {
        from: deployer,
        log: true
    })
    log(`You have deployed an NFT contract to ${SVGNFT.address}`)
    const svgNFTContract = await ethers.getContractFactory("SVGNFT")
    const accounts = await hre.ethers.getSigners()
    const signer = accounts[0]
    const svgNFT = new ethers.Contract(SVGNFT.address, svgNFTContract.interface, signer)
    const networkName = networkConfig[chainId]['name']

    log(`Verify with:\n npx hardhat verify --network ${networkName} ${svgNFT.address}`)
    log("Let's create an NFT now!")
    let filepath = "/mnt/c/Users/.../all-on-chain-generated-nft/all-on-chain-test/img/triangle.svg"
    let svg = fs.readFileSync(filepath, { encoding: "utf8" })
    log(`We will use ${filepath} as our SVG, and this will turn into a tokenURI. `)
    tx = await svgNFT.create(svg)
    await tx.wait(1)
    log(`You've made your first NFT!`)
    log(`You can view the tokenURI here ${await svgNFT.tokenURI(0)}`)
}

module.exports.tags = ['all', 'svg']

tell me if you need any more file!

PatrickAlphaC commented 3 years ago

Hmm... do you have a .env file with a mnemonic in it?

PatrickAlphaC commented 3 years ago

Please do NOT send me the contents of that file, just whether or not it's there

toufic0710 commented 3 years ago

Yes I have one, I filled it with my infura key, ethers can api key and private key.

PatrickAlphaC commented 3 years ago

Can you try re-cloning the repo and try again?

toufic0710 commented 3 years ago

I did it an got this error : image

I changed:

When I followed your tutorial I did not get that error.

dexmorg9 commented 3 years ago

If the svg contains double quotes, try replacing them with single quotes (')

PatrickAlphaC commented 3 years ago

Does that solve it?

toufic0710 commented 3 years ago

Replacing with single quotes did not work. When you told me to download again the repo, I did some changes mentionned above, but I also deleted deployment files (except 01_deploy_svgnft), as I only wanted to run the first part of the tutorial. However, I redownload the repo without deleting anything and now it is working :)

ChinmayGopal931 commented 2 years ago

I am also noticing this exact error. However I didn't clone the repo but I am manually doing each step with the tutorial. @PatrickAlphaC Not sure how to fix it.

ChinmayGopal931 commented 2 years ago
yarn hardhat deploy --show-stack-traces
yarn run v1.22.19
warning package.json: No license field
$ /home/chinmay/dev/governance/node_modules/.bin/hardhat deploy --show-stack-traces
Nothing to compile
No need to generate any newer typings.
----------------------------------------------------
Deploying GovernanceToken and waiting for confirmations...
An unexpected error occurred:

Error: ERROR processing /home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:
TypeError: Cannot read properties of undefined (reading 'length')
    at getFrom (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1713:14)
    at _deploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:533:9)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async _deployOne (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/helpers.ts:1004:16)
    at async Object.deployGovernanceToken [as func] (/home/chinmay/dev/governance/deploy/deploy-Governance-token.ts:14:27)
    at async DeploymentsManager.executeDeployScripts (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1219:22)
    at async DeploymentsManager.runDeploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at DeploymentsManager.executeDeployScripts (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async DeploymentsManager.runDeploy (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
    at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:438:5)
    at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:584:32)
    at async Environment._runTaskDefinition (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:219:14)
    at async Environment.run (/home/chinmay/dev/governance/node_modules/hardhat/src/internal/core/runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (/home/chinmay/dev/governance/node_modules/hardhat-deploy/src/index.ts:669:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@dexmorg9

choudharysachin90 commented 2 years ago

const { deployer } = await getNamedAccounts();

I was missing await and getting this error. soon I put it , it got resolved.

JovanMwesigwa commented 2 years ago

I was missing the await key in getNamedAccounts()

const { deployer } = await getNamedAccounts()
EECvision commented 2 years ago

const { deployer } = await getNamedAccounts();

I was missing await and getting this error. soon I put it , it got resolved.

Thank you!, it solved the issue.