Skip to content

Instantly share code, notes, and snippets.

@fvictorio
Last active April 8, 2024 09:46
Show Gist options
  • Save fvictorio/8f5e376a88d7ab9edefe47e8ffe14593 to your computer and use it in GitHub Desktop.
Save fvictorio/8f5e376a88d7ab9edefe47e8ffe14593 to your computer and use it in GitHub Desktop.
Hardhat "function call to a non-contract account" error

If you get this error in Hardhat:

Transaction reverted: function call to a non-contract account

It means that your transaction is (at some point) making a call to an address that is not a contract. There are two common scenarios where this happen.

Wrong argument

A simple example of how this could happen is if you have these two contracts:

contract Foo {
  function f() public {}
}

contract FooCaller {
  function callFoo(Foo foo) public {
    foo.f();
  }
}

And you execute this code:

const [signer] = await ethers.getSigners();

const Foo = await ethers.getContractFactory("Foo");
const foo = await Foo.deploy();
await foo.deployed();

const FooCaller = await ethers.getContractFactory("FooCaller");
const fooCaller = await FooCaller.deploy();
await fooCaller.deployed();

await fooCaller.callFoo(signer.address);

In this case, you'll get this error:

Error: Transaction reverted: function call to a non-contract account
    at FooCaller.callFoo (contracts/Foo.sol:7)

Did you catch the mistake? The last line of the script uses signer.address instead of foo.address.

Notice that the stack trace tells you exactly in which line the error was (contracts/Foo.sol:7). In this example is pretty obvious that that was the problematic line, but in more complex projects the stack trace should point you in the right direction.

Wrong network

Another common cause for this error is to assume that some contract exists when it doesn't. Typically this happens because you are accidentally using the wrong network. For example, maybe you are using Hardhat's forking mode, but you are forking the wrong network. If you are forking from a specific block number, it can also be the case that you are using an old block number and the contract you expect to exist hasn't been deployed yet.

@MubashirWaheed
Copy link

OK I posted my question here: https://ethereum.stackexchange.com/questions/149616/error-transaction-reverted-function-call-to-a-non-contract-account-when-callin
I even deployed my contract on goerli to see if I get the flashLoan and it works as intended: https://goerli.etherscan.io/tx/0x9db8879b9d8ff509d19534ad6e4e39a87619139aa4ffc853a6e0e6a50b479bec
Can't seem to figure out why it says no contract present even tho vault address is correct and I have hardcoded it in the contract so it's same on the polygon and goerli (where I tested).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment