简体   繁体   中英

On hardhat when deploying a contract or minting an NFT getting error: ProviderError: invalid sender

I am using HardHat to deploy contracts on Polygon (Matic), it works most of the time when deploying or minting.. but then it usually breaks when I switch from testnet to mainnet.

For example: I switched from mainnet to rpc-mumbai.maticvigil.com, then I get the error ProviderError: invalid sender.

Then I updated my hardhat.config.js to point to matic-mumbai.chainstacklabs.com and I am able to mint and deploy contracts with no errors.

I am reaching out to see if this is a known issue occurring with polygon and or hardhat?

Add this to your hardhat.config.js, after accounts:

 gasPrice: 8000000000, // default is 'auto' which breaks chains without the london hardfork

Full entry:

  matic: {
      url: "https://matic-mumbai.chainstacklabs.com",
      accounts: [PRIVATE_KEY],
      gasPrice: 8000000000, // default is 'auto' which breaks chains without the london hardfork
    }

Ref: https://github.com/nomiclabs/hardhat/issues/1828

Confirmed the solution of "The Vikk" is working. Added also the account details and 0x before the private key.

 mumbai: {
  url: "https://polygon-mumbai.g.alchemy.com/v2/<API_KEY>",
  accounts: [`0x${PRIVATE_KEY}`]
  }

I discovered the issue with "Invalid sender". This for me was that the wallet address had not sent any transactions and only had deposits from the testnet faucet. For whatever reason it made that error disappear when I sent a transaction manually through Metamask then sent it back then tried to issue the hardhat run command again.

From what I am now seeing however, the transaction still hangs without any errors and --verbose provides nothing useful. This appears to be some kind of conflict pertaining to the London Hardfork. I have not resolved the issue. Will report back later with more information if I have it.

What I have done so far:

  1. Tried adding gasPrice and/or gas to the hardhat.config.js networks.matic object
  2. Tried to put 0x in front of the privateKey
  3. Tried adding chainId:80001 to the hardhat.config.js networks.matic object
  4. Tried increasing gasPrice to over 500 gwei
  5. Tried 3 different RPC endpoints including a private one requiring an API key

Hardhat github made an update to 2.6.2, which also does not resolve the problem.

Same issue here. I've tried a private key generated from Vanity ETH as well as a private key from my MetaMask wallet. Also tried adding 0x prefix and with / without gasPrice but getting the same error.

Here's my config:

module.exports = {
  solidity: "0.8.2",
  networks: {
    mumbai: {
      url: "https://rpc-mumbai.maticvigil.com/",
      account: [process.env.PRIVATE_KEY],
      gasPrice: 8000000000,
    }
  }
};

Anyone have any luck figuring this out?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM