blockchainsmartcontractshardhatavalanche

Deploying to fuji network with hardhat creates HttpProviderError


I am having issue deploying contract to fuji c chain with hardhat. Here is my hardhat.config.js file:

const config: HardhatUserConfig = {
  networks: {
    fuji: {
      url: 'https://api.avax-test.network/ext/bc/C/rpc',
      chainId: 43113,
      gasPrice: 20000000000,
      accounts: [`0x${PRIVATE_KEY}`],
    },
    avalanche: {
      url: 'https://api.avax.network/ext/bc/C/rpc',
      chainId: 43114,
      gasPrice: 20000000000,
      accounts: [`0x${PRIVATE_KEY}`],
    },
  },
};

Here is the command for deploying the contract: npx hardhat run --network fuji scripts/deploy.ts I am getting the following error:

ProviderError: HttpProviderError
    at HttpProvider.request (E:\SolidityProject\Leveor\nft-platform-script\node_modules\hardhat\src\internal\core\providers\http.ts:78:19)

I also have used a different rpc url provided by infura with the API key but it gave the same error. How to resolve this?


Solution

  • The problem was setting the gasPrice on the hardhat config file. For the fuji network the gas is automatically calculated and explicitly setting a gas price causes the error ProviderError: HttpProviderError (The error message could be better). This is the same case for the Celo network. But for Ethereum, Polygon, and Binance smart chains you CAN explicitly define the gas price.