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.
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.
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.
I am also getting the
Error: Transaction reverted: function call to a non-contract account
when I run the test on the polygone fork in Hardhat.In my test, I deploy my contract and then call the
makeFlashLoan
function in my contract which in turn calls theflashloan
function on the vault contract from the balancer for flashloan.yes, I have checked that I am passing the correct address for the vault contract.