NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.25k stars 1.39k forks source link

Only absolute URLs are supported #2244

Closed skimaharvey closed 2 years ago

skimaharvey commented 2 years ago

Hello,

Here is the error i get when I try to deploy my contracts to rinkeby. No problem during compilation. I am confused about it. Any help is appreciated. Thank you.

TypeError: Only absolute URLs are supported
    at getNodeRequestOptions (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/node-fetch/lib/index.js:1327:9)
    at /Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/node-fetch/lib/index.js:1432:19
    at new Promise (<anonymous>)
    at fetch (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/node-fetch/lib/index.js:1429:9)
    at HttpProvider._fetchJsonRpcResponse (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/hardhat/src/internal/core/providers/http.ts:140:30)
    at HttpProvider.request (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)
    at GanacheGasMultiplierProvider._isGanache (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:317:30)
    at GanacheGasMultiplierProvider.request (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:306:23)
    at EthersProviderWrapper.send (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
    at getSigners (/Users/ski/Documents/buildspace/fork-pancake-swap/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:45:20)
fvictorio commented 2 years ago

Hi @skimaharvey, can you provide reproduction steps or a minimal reproducible example?

mazurbeam commented 2 years ago

I was having the same problem too.

We're deploying to polygon and I never had trouble deploying locally. When I tried to setup a CI pipeline is when i started getting the error. Had someone else clone the project and they started getting the same error too. I can't replicate it locally and we both use macs.

After playing with the deploy script and creating this minimal version, I found that it was the matic.balanceOf(adminAddress) call that was breaking things.

After replacing all those calls with the ethers Wallet getBalance, the rest of the script ran and was able to deploy.

Matic token contract from here lives next to our other contracts and everything complied fine.

/* External imports */
import { ethers } from 'hardhat'
import {
  BigNumber,
  Wallet
} from 'ethers'
import 'dotenv/config'

/* Internal imports */
import {MaticToken} from "../types";

let provider = new ethers.providers.JsonRpcProvider(
  process.env.INFURA_URL
)

let privateKey1: string = process.env.PRIVATE_KEY as string
let l1Wallet1: Wallet = new ethers.Wallet(privateKey1, provider)
const adminAddress = l1Wallet1.address

let matic: MaticToken
let adminMaticBalanceBefore: BigNumber

async function main() {
  console.log('wallet', l1Wallet1)

  matic = await ethers.getContractAt(
    'IERC20',
    '0x0000000000000000000000000000000000001010'
  ) as MaticToken

  console.log('matic', matic)

  const balance = await l1Wallet1.getBalance()
  // works
  console.log('balance', balance)

  // does not work in CI
  adminMaticBalanceBefore = await matic.balanceOf(adminAddress)
  console.log('adminMaticBalanceBefore', adminMaticBalanceBefore)

}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
johnuphoff commented 2 years ago

@skimaharvey if you are using the .env.template, make sure you rename it from .env.template to .env. It sounds to me like maybe you have an Infura URL or similar configured for RINKEBY_URL and it is maybe undefined which is throwing in the fetch call.

fvictorio commented 2 years ago

Uhm, this seems like a config validation issue we are not catching. Again: if someone can provide reproduction steps, it would be very useful.

PopusoiIonut commented 2 years ago

Got the same issue here, the contract was compiled with no errors, but when atempt to deploy on ropsten network I get the error code, file is in /Users/computer/my-nft/node_modules/loupe/index.js : ypeError: Only absolute URLs are supported at getNodeRequestOptions (/Users/computer/my-nft/node_modules/node-fetch/lib/index.js:1327:9) at /Users/computer/my-nft/node_modules/node-fetch/lib/index.js:1440:19 at new Promise () at fetch (/Users/computer/my-nft/node_modules/node-fetch/lib/index.js:1437:9) at HttpProvider._fetchJsonRpcResponse (/Users/computer/my-nft/node_modules/hardhat/src/internal/core/providers/http.ts:140:30) at HttpProvider.request (/Users/computer/my-nft/node_modules/hardhat/src/internal/core/providers/http.ts:55:29) at GanacheGasMultiplierProvider._isGanache (/Users/computer/my-nft/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:317:30) at GanacheGasMultiplierProvider.request (/Users/computer/my-nft/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:306:23) at EthersProviderWrapper.send (/Users/computer/my-nft/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20) at getSigners (/Users/computer/my-nft/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:45:20)

fvictorio commented 2 years ago

Again: nothing we can do here without a minimal reproducible example. Sorry.

fvictorio commented 2 years ago

Closing this for now. If someone has precise and minimal reproduction steps, please let us know.

cpecorari commented 2 years ago

Keep closed but: Ended up in this thread because of a colleague not copying the .env.example to .env, ended up using empty string for mainnet url to fork with hardhat. So definitely not really a hardhat error, should be a clearer error message maybe, but user error ;)

fvictorio commented 2 years ago

Oh that's really interesting @cpecorari. I will open a new issue for that.

Shymaa-Arafat commented 2 years ago

I had this same issue trying to run a smart contract on a docker environment, I used Alchemy node and named a respiratory with the same GitHub respiratory name, but I used the docker start up alpine git I found the question raised in many places all talking about the "fetch" command. Honestly, I don't know where to find or add the fetch command, in what file?

fvictorio commented 2 years ago

@Shymaa-Arafat this error usually happens because the URL used was an empty string or some filler value like "url". Read the discussion in this issue for the details.