9

I have an ERC721 contract on rinkeby and need to test the mint function, but sometimes I receive the fallowing error:

Error: cannot estimate gas; transaction may fail or may require manual gas limit ... code=UNPREDICTABLE_GAS_LIMIT

This is my code:

const tx2 = await nft.connect(alice).mintPublicSale(1, {value: ethers.utils.parseEther("0.04")});
await tx2.wait();

My wallet is already funded.

1

8 Answers 8

4

I got this error because I was using the wrong contract address. I was using the contract's mainnet address instead of it's Ropsten address. Make sure you have the right addresses for the network you're working with.

4

In your hardhat.config.js add the following two params in your test network block

   gas: 2100000,
   gasPrice: 8000000000,
2

in the function your calling add {gasLimit: 5000000} to the parameter

1

I also faced similar problem, there was a bug in my code, which caused the following error.

Error: cannot estimate gas; transaction may fail or may require manual gas limit

This error is because the transaction was not complete and the contract (or the function called) failed.

Fixing the bug in my contract and re-deploying helped me get rid of this error.

3
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 13, 2021 at 21:40
  • What was your bug? I can't find any bug, and when I'm using remix it works.
    – n3n3
    Dec 14, 2021 at 12:15
  • My bug was something trivial. I had similar looking functions with changed variables, and while doing so, I forgot to rename a variable and that was causing the issue.
    – 25b3nk
    Dec 16, 2021 at 5:33
0

You may also need to check and change the network you account is connected to on the metamask. I was one of the standard testnet like ropsten and rinkeby instead of localhost where my contract was deployed to.

0

I had the same error and the solution was to go to https://faucets.chain.link/rinkeby and top up, it linked my MetaMask account in the process and I didn't have to change the code

enter image description here

0

I had this error, then checked my metamask for the balance, and found out my wallet was hacked and someone drained my test funds

0

Same problem.

I solved it in this way.

  1. Create a new directory totally empty: /blabla/createsmartaccount_dir.

  2. Create these 2 files inside it.

/blabla/createsmartaccount_dir/index.js

/blabla/createsmartaccount_dir/package.json

  1. Run the commands

npm install

node ./index.js

#/blabla/createsmartaccount_dir/index.js

const { ethers } = require( 'ethers')
const { EthersAdapter } = require(  '@safe-global/protocol-kit')
const Safe = require(  '@safe-global/protocol-kit')
const { SafeFactory } = require(  '@safe-global/protocol-kit')
const { SafeAccountConfig } = require(  '@safe-global/protocol-kit')
const { ContractNetworksConfig } = require(  '@safe-global/protocol-kit')

const execute = async () => {
    const RPC_URL='https://rpc2.sepolia.org'
    const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
    
    
    
    // Initialize signers
    //metamask wallet and privatekey
    //0x967c1CF5d91f3738c969c76EB4bDddA6da4183c1
    const signerWallet = 
new ethers.Wallet("ca46xxxxxxxxxxxxxxx", provider)

    const ethAdapter = new EthersAdapter({ethers, signerOrProvider: signerWallet})
    
    const chainId = await ethAdapter.getChainId()
    console.log(`ChainId: ${chainId}`)

    
  
    
    const safeVersion = '1.3.0'
    const isL1SafeMasterCopy = false
    const safeFactory = await SafeFactory.create({ ethAdapter: ethAdapter })



    const safeAccountConfig = {
        threshold: 1, // Have to be >= 1 && <= totalOwners
        owners: ["0x967xxxxxxxxxxxxxxxxxxxxxxxxxxxx"],
        eth_estimateGas:30000,
    }
    console.log("Start Deploying Safe");



    
    
    //This Safe is tied to owner 1 because the factory was initialized with an 
    //adapter that had owner 1 as the signer. 
  
    const safeSdkOwner1 = await safeFactory.deploySafe({ safeAccountConfig })

    const safeAddress = safeSdkOwner1.getAddress()

    console.log(`Safe deployed at: ${safeAddress}`)  
}
execute();

#/blabla/createsmartaccount_dir/package.json

{
  "dependencies": {
    "@safe-global/api-kit": "^1.0.1",
    "@safe-global/protocol-kit": "^0.1.1",
    "@safe-global/safe-core-sdk-types": "^1.10.1",
    "dotenv": "^16.0.3",
    "ethers": "5.7.2"
  }
}

Periodic failure when attempting to create gnosis safe via @safe-global/protocol-kit SDK

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.