When i want to deploy my contract with this command:

npx hardhat run --network goerli scripts/deploy.js

I get this error:

ProviderError: HttpProviderError at HttpProvider.request (/Users/alirezamac/Documents/Token-dex/node_modules/hardhat/src/internal/core/providers/http.ts:78:19)

And here is my config file:

require ("dotenv").config()

module.exports = {
  solidity: "0.8.17",
  networks: {
    goerli: {
      url: process.env.INFURA_GOERLI_ENDPOINT,
      accounts: [process.env.PRIVATE_KEY],
      chainId: 5

and also this is my deploy file:

const hre = require("hardhat");

async function main() {
 const Token = await hre.ethers.getContractFactory("MyToken")
 const token = await Token.deploy();
 await token.deployed()
console.log("Congratulations!! Your token deployed, Here's token address:", token.address);

 const Dex = await hre.ethers.getContractFactory("Dex2")
 const myDex = await Dex.deploy(token.address)
 await token.deployed()

 console.log("Here's your dex contract address:", myDex.address);

main().catch((error) => {
  process.exitCode = 1;
  • seems like it's an issue with your infura url make sure that is correct first, and then my second idea would be that it is not reading the url from the .env file correctly. To test that change the url to your actual url and if it works then there is an issue with your .env setup are you using vanilla js or a framework like react? Commented Dec 5, 2022 at 13:58

4 Answers 4


You can add some lines to node_modules/hardhat/internal/core/providers/http.js to debug. After every isErrorResponse check add: console.log(response) or console.log(jsonRpcResponse).

Most likely it's an error inside your contracts or deploy script (or both).


Thre is a typo in await token.deployed() should be myDex.deployed()

That could be the reason the provider is reverting without any reason


Solved this error by looking the ganache's console and seeing that the tx was reverted due to an error caused by incorrect assignment of an account to a role.


Please check if your testnet URLs are correct. If all of them are correct, then verify if you have named your environment variable configuration file as .env.example. If it is named .env.example, change the file name to .env. Then try to deploy it should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.