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 reckon its the latter of the two.
I am using IUniswapV3Factory(uniswapfactoryAddress).createPool. This should create a pool, however if the contract address does not exist in the hardhat network, it will not. I posted on the disc server and made a thread, indicating the error when I run:
yarn coverage --network rinkeby.
please let me know if you would rather we continue here or on disc!