PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

01-deploy-fund-me gives an error: expected 1 constructor arguments, got 42 [Tutorial Time: 10:59:00] #41

Closed nachoddiaz closed 2 years ago

nachoddiaz commented 2 years ago

I am at moment 10:59:00 in the tutorial, I try tu run:

 yarn hardhat deploy --network rinkeby

and it returns me this:

Error: ERROR processing /home/nachoddiaz/Curso32/hardhat-fund-me/deploy/01-deploy-fund-me.js:
Error: expected 1 constructor arguments, got 42

Here is my code:

01-deploy-fund-me.js

const { networkConfig, devChains } = require("../helper-hardhat-config.js")
const { getNamedAccounts, deployments, network } = require("hardhat")
const { verify } = require("../utils/verify.js")

//Podemos resumir las dos lineas anteriores en una sola
module.exports = async ({ getNamedAccounts, deployments }) => {
  const { deploy, log } = deployments
  const { deployer } = await getNamedAccounts()
  const chainId = network.config.chainId

  let ETHUSDPriceAddress //ponemos let para poder actualiarla
  if (devChains.includes(network.name)) {
    //Si estamos en devChain, desplegamos mock
    const ETHUSDAgregator = await deployments.get("MockV3Aggregator")
    ETHUSDPriceAddress = ETHUSDAgregator.address
  } else {
    //Si no estamos en devChain, desplegamos normal
    ETHUSDPriceAddress = networkConfig[chainId]["ETHUSDPrice"]
  }

  const args = ETHUSDPriceAddress

  //cuando trabajemos localhost o en la red hardhat, usaremos un mock
  const fundMe = await deploy("FundMe", {
    from: deployer,
    args: args, // estos argumentos se le pasan al constructor
    log: true,
    waitConfirmations: network.config.blockConfirmations || 1
  })

  if (!devChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
    await verify(fundMe.address, args)
  }
  log(
    "----------------------------------------------------------------------------------------------"
  )
}

module.exports.tags = ["all", "fundme"]

hardhat.config.js

require("@nomicfoundation/hardhat-toolbox")
require("hardhat-deploy")
require("dotenv").config()
require("hardhat-gas-reporter")

const Rinkeby_URL = process.env.Rinkeby_RPC_URL
const PRIVATE_KEY_RINKEBY = process.env.Private_KEY
const CMC_API_KEY = process.env.CMCAPI
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY

module.exports = {
  //solidity: "0.8.9",
  networks: {
    rinkeby: {
      url: Rinkeby_URL,
      accounts: [PRIVATE_KEY_RINKEBY],
      chainId: 4,
      blockConfirmations: 6 // esperamos 6 para que a etherscan le de tiempo a indexar nuestra TX
    }
  },
  solidity: {
    compilers: [{ version: "0.8.8" }, { version: "0.6.6" }]
  },
  defaultNetwork: "hardhat",
  gasReporter: {
    enabled: true,
    outputFile: "gas-report.txt",
    noColors: true,
    currency: "USD",
    coinmarketcap: CMC_API_KEY,
    token: "MATIC"
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY
  },
  namedAccounts: {
    deployer: {
      default: 0
    },
    users: {
      default: 0
    }
  }
}

I have spent half an hour trying to solve it, after I have searched on stack exchange but I have not found the answer. I hope you can help me. thanks.

nicolasCinzer commented 2 years ago

Hi Nacho! I think your error comes with the fact that you are passing an object instead an array to the deploy!

 const args = ETHUSDPriceAddress

Try wrap it with some brackets like this

 const args = [ETHUSDPriceAddress]

Why i think this? Well, the error is saying that you are passing 42 args instead of one, i suppose that when you pass an string (in this case, the price feed address) the deploy is chunk it up the string into an array with each letter (42 letters string == 42 elements array). So try that and hit me up if its resolve the problem! If you dont understand please let me know, im from Argentina as well so i can explain this to you in spanish!

Best Regards! Saludos wachin!

nachoddiaz commented 2 years ago

Sí, ahí estaba el problema. Estaba tratando cada carácter por separado. Muchas gracias compañero.

nicolasCinzer commented 2 years ago

Genial! Dale de baja al problema o marcalo como respondido!

Saludos.