How to deploy UniswapV2 on ganache

Hello there,

I m trying to learn Uniswap and when I deploy contract UniswapV2Router02.sol via truffle, it always returns me error out of gas, even I tried to increase very high gasLimit and also run on ganache. I think the problem here is the size of the contract very large. Below is a detailed of error:

   * gas required exceeds allowance (80000290) or always failing transaction.
   * Try: + using the '--dry-run' option to reproduce this failure with clearer errors.
          + verifying that your gas is adequate for this deployment.

Is there anything wrong? Any instruction to deploy this contract?


1 Like

Hi @jamestran,

Welcome to the community :wave:

You may want to check with Uniswap if they have instructions on deploying to a local environment:

As the constructor takes two addresses and sets them, assuming you are providing addresses there isn’t much that can error in the constructor, so assume it is a size issue.

You could try running ganache-cli with --allowUnlimitedContractSize

You could try enabling the optimizer and setting runs to 1.

1 Like

Thanks, I will try allowUnlimitedContractSize

1 Like

Hi everyone, I want to lets you know that I have been successfully deployed UniswapV2Router02.sol by set truffle config as below:

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: {
       "*": {
         "": [
         "*": [

Here the tx:

1 Like

Hi @jamestran

Thanks for sharing. :pray: