SHADAB IQBAL
SHADAB IQBAL

Reputation: 33

import { ethers } from "ethers" vs const { ethers } = require("hardhat")

I am working on an NFTMarketplace project with the guidance of a tutorial, where I am obviously requiring "ethers.js".

In my test.js file (which I run using npx hardhat test), it is required to use const { ethers } = require("hardhat");. On the other hand, in the Home.js (which is for react frontend), I am required to use import { ethers } from "ethers".

Now my question is, why I'm importing the same thing in 2 different ways.

Upvotes: 1

Views: 2719

Answers (1)

KeoooDev
KeoooDev

Reputation: 576

When using hardhat you do not need to import "ethers"

The Hardhat Runtime Environment, or HRE for short, is an object containing all the functionality that Hardhat exposes when running a task, test or script. In reality, Hardhat is the HRE.

https://hardhat.org/advanced/hardhat-runtime-environment?utm_source=buildspace.so&utm_medium=buildspace_project

Upvotes: 1

Related Questions