0

Starting to work with a uniswap simple fork using truffle and ganache, and when running:

truffle migrate --reset

I am having this:

Error: Returned error: VM Exception while processing transaction: revert
    at module.exports (/var/www/html/uniswap/core/migrations/2_deploy_contracts.js:23:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
Truffle v5.1.44 (core: 5.1.44)
Node v8.17.0

Compilation was good so far, and ganache is loaded.

Also I installed the openzeppelin library for Token1 and Token2 contract

The error seems to happen on createPair method.

Testing the contracts looks like the failure happens on this solidity line:

IUniswapV2Pair(pair).initialize(token0, token1);

But I checked the token values and seems to be created fine.

Here it is the full output:

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'development'
> Network id:      1601793094416
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.js
======================

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0x4fb4b21d2027a322007e1f6baddcd3b4297eeb056b1578e51b2065817c0171e8
   > Blocks: 0            Seconds: 0
   > contract address:    0x174B3B88E5BC6384e5d6a3f6361c1dE08530CB46
   > block number:        47
   > block timestamp:     1601794571
   > account:             0x1Bd55dfB97737246e924A7817FF9105c3b539dFa
   > balance:             98.63353568
   > gas used:            221555 (0x36173)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0044311 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:           0.0044311 ETH


2_deploy_contracts.js
=====================

   Replacing 'UniswapV2Factory'
   ----------------------------
   > transaction hash:    0x8008a6b4dc127546de32f80e4410c7bddab6d79eb1f04bb0056de14edff0cb74
   > Blocks: 0            Seconds: 0
   > contract address:    0xa44f9937Eb97eAA8D177fF288fb2ad357bbA7B3c
   > block number:        49
   > block timestamp:     1601794571
   > account:             0x1Bd55dfB97737246e924A7817FF9105c3b539dFa
   > balance:             98.53171312
   > gas used:            5049130 (0x4d0b2a)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.1009826 ETH


   Replacing 'Token1'
   ------------------
   > transaction hash:    0x743f8d49e2ac6d1efe4186abf5250c98f3e4c246dfedb2cd86d33453d31d7a61
   > Blocks: 0            Seconds: 0
   > contract address:    0xdc660AE67657C80Eb467256796011a1650bE2221
   > block number:        50
   > block timestamp:     1601794571
   > account:             0x1Bd55dfB97737246e924A7817FF9105c3b539dFa
   > balance:             98.50611422
   > gas used:            1279945 (0x1387c9)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0255989 ETH


   Replacing 'Token2'
   ------------------
   > transaction hash:    0x8eeaf3b763940b57ad18c716d8e638ca7b984493f7aac2c707bfdb62039287f1
   > Blocks: 0            Seconds: 0
   > contract address:    0x78b4e2e0b46fF97536F5ecb1d238d229732492F6
   > block number:        51
   > block timestamp:     1601794571
   > account:             0x1Bd55dfB97737246e924A7817FF9105c3b539dFa
   > balance:             98.48051532
   > gas used:            1279945 (0x1387c9)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.0255989 ETH

token1Address
0xdc660AE67657C80Eb467256796011a1650bE2221
token2Address
0x78b4e2e0b46fF97536F5ecb1d238d229732492F6

Error: Returned error: VM Exception while processing transaction: revert
    at module.exports (/var/www/html/uniswap/core/migrations/2_deploy_contracts.js:28:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
Truffle v5.1.44 (core: 5.1.44)
Node v8.17.0

and here it is the full code for 2_deploy_contracts.js

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

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

  let token1Address, token2Address;

  if (network=="mainnet") {
    token1Address = '';
    token2Address = '';
  } else {
    await deployer.deploy(Token1);
    await deployer.deploy(Token2);
    const token1 = await Token1.deployed();
    const token2 = await Token2.deployed();
    token1Address = token1.address;
    token2Address = token2.address;
  }

  console.log("token1Address");
  console.log(token1Address);
  console.log("token2Address");
  console.log(token2Address);

  await factory.createPair(token1Address, token2Address);

};

Any idea would be appreciated

Thank you very much in advance.

2 Answers 2

1

I'm also trying to do a fork of Uniswap and got an error when running truffle migrate. It errors out when deploying the Migrations contract: VM Exception while processing transaction: invalid opcode at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:97:1) at process._tickCallback (internal/process/next_tick.js:68:7)

I was able to fix it by updating ganache-cli from 6.1.8 to 6.11.0 , maybe this will help.

1
  • That actually helped. I had 6.4.3 and I updated ganache to 6.12. Problem solved :)
    – Donut
    Oct 16, 2020 at 11:47
0

This solved the problem

npm i -g [email protected]

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.