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.


8 Answers 8


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.


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

   gas: 2100000,
   gasPrice: 8000000000,

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


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.

  • 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
    Commented 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
    Commented 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
    Commented Dec 16, 2021 at 5:33

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.


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


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


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.



  1. Run the commands

npm install

node ./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
    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"],
    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}`)  


  "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.