Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'getContractFactory') al probar el contrato

La primera pregunta es tan clara conmigo si no está muy clara, pero haré lo mejor que pueda.

Actualmente estoy viendo un video de YouTube para probar mi contrato con hardhat, ethers y waffle ( https://www.youtube.com/watch?v=oTpmNEYV8iQ&list=PLw-9a9yL-pt3sEhicr6gmuOQdcmWXhCx4&index=6 ).

Aquí está el contrato:

 // SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; contract MyContract is ERC721 { constructor(string memory name, string memory symbol) ERC721(name, symbol) { } }

Y aquí está test.js:

 const { expect } = require('chai'); describe("MyContract", function() { it("should return correct name", async function() { const MyContract = hre.ethers.getContractFactory("MyContract"); const myContractDeployed = await MyContract.deploy("MyContractName", "MCN"); await myContractDeployed.deployed(); expect(await myContractDeployed.name()).to.equal("MyContractName"); }); });

cuando ejecuto "npx hardhat test" en la terminal, devuelve:

 MyContract 1) should return correct name 0 passing (7ms) 1 failing 1) MyContract should return correct name: TypeError: Cannot read properties of undefined (reading 'getContractFactory') at Context.<anonymous> (test\test.js:7:35) at processImmediate (node:internal/timers:464:21)

Mi código coincide con el del video, y me está costando entender por qué obtengo un TypeError aquí. ¡Cualquier orientación es muy apreciada!

EDITAR:

De alguna manera lo arreglé, no entiendo cómo lo arregló exactamente, pero lo hizo. En lugar de simplemente instalar

 npm install @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

lo instalé

 npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

Entonces la terminal imprimió

 npm WARN idealTree Removing dependencies.@nomiclabs/hardhat-waffle in favor of devDependencies.@nomiclabs/hardhat-waffle npm WARN idealTree Removing dependencies.ethereum-waffle in favor of devDependencies.ethereum-waffle npm WARN idealTree Removing dependencies.@nomiclabs/hardhat-ethers in favor of devDependencies.@nomiclabs/hardhat-ethers npm WARN idealTree Removing dependencies.ethers in favor of devDependencies.ethers

luego eliminé el hre frente a ethers.getContractFactory("MyContract") ¡y funcionó! Si alguien quisiera explicar por qué esto podría haberlo solucionado, estaría feliz de leerlo, de lo contrario, seguiré adelante.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Agregue el siguiente fragmento de código en la parte superior de su archivo hardhat.config.js

 require("@nomiclabs/hardhat-waffle");
about 4 years ago · Juan Pablo Isaza Report

0

Necesitabas importar hre en el código de prueba.

 const hre = require("hardhat");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!