I am trying to fork Uniswap and deploy on Ropsten testnet for educational and testing purposes. From what I gathered, it seems that we need to first deploy the UniswapV2Factory contract, followed by the UniswapV2Router02 contract. I cloned both from here and here respectively. I haven't made any changes to the code. I can deploy the factory contract just fine using truffle. However, I am getting the following error while deploying the router contract.:

Error: *** Deployment Failed ***

"UniswapV2Router02" -- Cannot create instance of UniswapV2Router02; no code at address 0xXXXXXXXXXXXXXX.

This is the script I am using to deploy UniswapV2Factory:

const Factory = artifacts.require("UniswapV2Factory.sol");

module.exports = async function (deployer, network, addresses) {
  await deployer.deploy(Factory, addresses[0]);


and the code to deploy UniswapV2Router02:

const Router = artifacts.require('UniswapV2Router02.sol');

module.exports = async function (deployer, network, addresses) {
    const WETH_ADDRESS = '0x0a180a76e4466bf68a7f86fb029bed3cccfaaac5';  
    const FACTORY_ADDRESS = '{factory address}';

    await deployer.deploy(Router, FACTORY_ADDRESS, WETH_ADDRESS);

I have changed the solidity compiler version to 0.5.16 for the factory and 0.6.6 for the router.

3 Answers 3


I have found the solution (thanks to jamestran from openzeppelin forum).

jamestran solution:

compilers: {
   solc: {
     version: "0.6.6",    // Fetch exact version from solc-bin (default: truffle's version)
     // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
     settings: {          // See the solidity docs for advice about optimization and evmVersion
      optimizer: {
        enabled: true,
        runs: 999999
      evmVersion: "istanbul", 
      outputSelection: {
       "*": {
         "": [
         "*": [

P/S set to your truffle config.


I was also having same issue while deploying. When checked the tx hash that returned with error in the blockchain explorer, I got this :-

TX failed

This says the reason is 'maximum code size exceeded'.

The uniswapV2Router02 is a bulky code, that's why it fails to deploy. The tx is not able to go through, they tried to create an instance at that address, but could not make it. So returned an error. You may see that the contract address in the error messege is same as the contract address in the failed tx.


I fixed this by commenting out parts of the smart contract that are not used too often. I commented out (select code then (cntrl+/)) a whole section in the code, starting with this =>

**** SWAP (supporting fee-on-transfer tokens) ****

If you want this functionality, better copy this into a separate solidity file and import that into the Router solidity code.


Use the optimizer with at least 400 runs, it should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.