I am fairly new to smart contracts and am currently experimenting using Ganache and Truffle to test on my local machine.

My goal would be to have the smart contract interacting with other existing smart contracts on the Ethereum Mainnet, for example the UniswapV2Factory.sol, WETH9.sol and others. To test if my methods are working correctly, I also need to deploy those contracts to my local blockchain. This is where I am having trouble.


I have tried different things:

  1. Create one truffle project and put every contract, library and interface i need in the contracts directory. This gives me trouble compiling the contracts, since some need solidity version 4.xx, 5.xx and 6.xx.

  2. Create a seperate truffle project for each contract 'group' and set the solidity compiler version accordingly. This compiles and migrates fine and I can see all contracts appearing in the Ganache GUI. But when using the Truffle console I can only interact with the contracts from one project at a time.


What is the best approach when trying to test your smart contract against currently existing ones on mainnet locally?

1 Answer 1


Use ganache mainnet fork. Check this repo https://github.com/t4sk/defi-by-example#test

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.