question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simulating transactions on Ganache v7 fork throws insufficient funds error

See original GitHub issue

hey there, appreciate your work on this amazing tool! when trying to integrate the latest version (ganache 7.0.0) into my previously working code (which used ganache-core 2.13.2) I am seeing some non-deterministic behaviour. Sometimes when simulating a transaction on a fork it will throw an insufficient funds for intrinsic transaction cost error. But other times, running the exact same code will work as expected. Here is what I am doing:

const provider = new ethers.providers.Web3Provider(ganache.provider({
    fork: {
      url: MY_INFURA_URL,
      blockNumber: SOME_BLOCK_NUMBER
    },
    wallet: {
      unlockedAccounts: [USER_ADDRESS]
    }
  }) as any)
const tetherContract = new ethers.Contract(TETHER_ADDRESS, TETHER_ABI, provider.getSigner(USER_ADDRESS))
const userTetherBalance = await tetherContract.balanceOf(USER_ADDRESS)
const tx = await tetherContract.transfer(USER2_ADDRESS, userTetherBalance) //<---- throws error here

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
haseebrabbanicommented, Jan 29, 2022

Appreciate the explanation! However, since this code will be client-facing I wouldn’t want to use this workaround (and possibly link to this issue in a comment to explain why I’m setting maxFeePerGas). As such, I will hold off on integrating Ganache v7 and stick to ganache-core for the time being until a longer-term fix is implemented. Ideally, since users did not have to set this parameter before, they shouldn’t have to set it in the latest version either

1reaction
MicaiahReidcommented, Jan 27, 2022

Hi @haseebrabbani, we did some looking into this and think there’s a combination of factors contributing to the issue. If you change your transfer call to include a maxFeePerGas, as follows:

const tx = await tetherContract.transfer(
  USER2_ADDRESS,
  userTetherBalance,
  { maxFeePerGas: 90417983619 }
);

all of the transfers work. Whenever you fork from a block, the new “latest” block is used to set the baseFeePerGas of the next block. When no gas information is specified on a transaction, the default base fee is set by Ganache. This is an expensive gas premium because it ensures it will make it onto the block - but you’re overspending on gas in that case. So, this was leading to insufficient funds to perform the transfer.

We plan to improve upon this in a number of ways:

  • add the eth_feeHistory RPC method to help set those parameters (#1470)
  • add the option to set a configurable, static baseFeePerGas #1573

@haseebrabbani Let me know if the above fix doesn’t work for you and we can investigate further. If it does work, feel free to close this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

insufficient funds for intrinsic transaction cost
I have been trying to deploy an NFT contract through my terminal. However, it keeps giving me the error message: reason: 'insufficient funds...
Read more >
Is there a way to solve this insufficient funds for gas when ...
This should be an issue with insufficient account balance. Try sending the same transaction using an high-level function like transact() to ...
Read more >
ConsenSys/truffle - Gitter
Hi, While running truffle unbox react, it works fine till "cleaning up temporary files", but shows error as "Unbox failed" for "setting up...
Read more >
Mastering Blockchain, Second Edition
A hard fork was required on the Ethereum blockchain to reverse the impact of the hack and initiate the recovery of the funds....
Read more >
Mastering Ethereum
ETH, you want to send 1 ETH, so why is MetaMask saying you have insufficient funds? The answer is because of the cost...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found