Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpProviderError problem #3209

Closed
SunjidulNiloy opened this issue Sep 23, 2022 · 18 comments
Closed

HttpProviderError problem #3209

SunjidulNiloy opened this issue Sep 23, 2022 · 18 comments

Comments

@SunjidulNiloy
Copy link

SunjidulNiloy commented Sep 23, 2022

require("@nomiclabs/hardhat-waffle");
require("dotenv").config();

const { API_URL, PRIVATE_KEY } = process.env;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  networks: {
    avaxchain: {
      url: API_URL,
      accounts: [`0x${PRIVATE_KEY}`],
       },
  },

  solidity: {
    version: "0.8.6",
    settings: {
      optimizer: {
        enabled: true,
        runs: 1,
      },
    },
  },  
};

So I am having a problem deploying the contract on the avalanche test net, whenever I try to--> npx hardhat run scripts/deploy.js --network avaxchain
it shows an error of ---> error: ProviderError: HttpProviderError
Any suggestion?

@github-actions
Copy link
Contributor

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: e32f998c-e91f-4feb-b7e8-2f38ee7002d3

@sisco0
Copy link
Contributor

sisco0 commented Sep 24, 2022

After researching the topic, I found out that dotenv does not allow you to use destructuring for the process.env object.

A solution was provided by parceljs developers for their environment reader (see the PR linked in parcel-bundler/parcel#2191 for reference). However, no solution for dotenv seems to be active yet.
In that sense, the following URL could be checked as a reference mrsteele/dotenv-webpack#70.

Could you kindly retest by using the code snippet at the end of the current message and share the outcome?

  networks: {
    avaxchain: {
      url: process.env.API_URL,
      accounts: [`0x${process.env.PRIVATE_KEY}`],
       },
  },

@SunjidulNiloy
Copy link
Author

error: ProviderError: HttpProviderError same problem

Do I have to add process.env on the .env file as well?

but that also gives error

Error HH8: There's one or more errors in your config file:
  * Invalid value undefined for HardhatConfig.networks.avaxchain.url - Expected a value of type string.        
  * Invalid account: #0 for network: avaxchain - private key too short, expected 32 bytes

To learn more about Hardhat's configuration, please go to https://hardhat.org/config/

@sisco0
Copy link
Contributor

sisco0 commented Sep 25, 2022

Could you kindly share us an .env file sample content?
Modify the fields in the regions you see convenient for privacy purposes.

@SunjidulNiloy
Copy link
Author

sure

process.env.PRIVATE_KEY = 
process.env.API_URL = https://api.avax-test.network/ext/bc/C/rpc

@sisco0
Copy link
Contributor

sisco0 commented Sep 25, 2022

Could you kindly remove the process.env. portion in your .env lines and retry?
The file content should be something like as follows:

PRIVATE_KEY = YourPrivateKey
API_URL = https://api.avax-test.network/ext/bc/C/rpc

@SunjidulNiloy
Copy link
Author

SunjidulNiloy commented Sep 25, 2022

error: ProviderError: HttpProviderError

this error occurs

@LuisUrrutia
Copy link

I think that u didn't understand what @sisco0 is talking about.

dotenv does not allow you to use destructuring for the process.env object.

That means that you can't do this:
const { API_URL, PRIVATE_KEY } = process.env;

You have to access the value directly.
process.env.PRIVATE_KEY

So your example should look something like this:

require("@nomiclabs/hardhat-waffle");
require("dotenv").config();

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  networks: {
    avaxchain: {
      url: process.env.API_URL,
      accounts: [`0x${process.env.PRIVATE_KEY}`],
       },
  },

  solidity: {
    version: "0.8.6",
    settings: {
      optimizer: {
        enabled: true,
        runs: 1,
      },
    },
  },  
};

@SunjidulNiloy
Copy link
Author

Thank you for the info @LuisUrrutia , used your code but the same error occurs error: ProviderError: HttpProviderError

@fvictorio
Copy link
Member

After researching the topic, I found out that dotenv does not allow you to use destructuring for the process.env object.

For the record, this is only true if you are using certain bundle tools. That's not the case for Hardhat; destructuring process.env should work just fine.

@Gizmolala your problem is likely an error in the node, but we have a bug were we are swallowing the proper error message returned by it, which will make it hard for you to debug this.

A super hackish thing you can try is this:

  • Open the node_modules/hardhat/internal/core/providers/http.js file
  • Search for the line that says if (isErrorResponse(jsonRpcResponse)) {
  • Below that line, add console.log("error --->", jsonRpcResponse)

This should log the actual error you are getting.

I know this is a shitty workaround, and properly fixing this is high on our priority list.

@SunjidulNiloy
Copy link
Author

Same error Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas",
error: ProviderError: HttpProviderError

@fvictorio
Copy link
Member

@Gizmolala sorry, I wasn't clear, I meant that you should see something that starts with error ---> in the output, and that that should explain what's going on. That change is just a hack to get more information, not an actual fix.

@SunjidulNiloy
Copy link
Author

You mean add this line console.log("error --->", jsonRpcResponse) below this line if (isErrorResponse(jsonRpcResponse)) {
and then in terminal npx hardhat run scripts/deploy.js --network avaxchain to show the output right?

@fvictorio
Copy link
Member

Yes

@SunjidulNiloy
Copy link
Author

SunjidulNiloy commented Sep 30, 2022

did that

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas",
error: ProviderError: HttpProviderError

@github-actions github-actions bot added the Stale label Oct 30, 2022
@RohitKS7
Copy link

@Gizmolala Try adding gasPrice manually like this

        avaxchain: {
            url: RPC_URL,
            gasPrice: 225000000000,
        },

@github-actions github-actions bot removed the Stale label Nov 10, 2022
@codingwithmanny
Copy link

From my understanding I thoughts that why we have these settings, but please correct me if I wrong in terms of these setting estimating the gas price as well:

{
      gasPrice: "auto",
      gas: "auto",
      allowUnlimitedContractSize: true,
}

@fvictorio fvictorio removed their assignment Dec 27, 2022
@fvictorio
Copy link
Member

Closing this in favor of #1222, because I think that the main issue here is that we are not showing the error message returned by the node.

@fvictorio fvictorio closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

6 participants