I have forked sushiswap recently from the repo. I am getting the following error when calling createPair() from UniswapV2Factory.sol during my deployment, the code has not been touched and I have no idea where I am going wrong.

The error: Error: Returned error: VM Exception while processing transaction: revert

The deployment:

// Uniswap
const Factory = artifacts.require('Uniswapv2/UniswapV2Factory.sol');

const WETH = artifacts.require('WETH.sol');

// Testing
const MockERC20 = artifacts.require('MockERC20.sol');

module.exports = async function(deployer, network, accounts) {
    const [admin, _] = accounts;

    // Test Tokens
    const tokenA = await MockERC20.new('TokenA', 'TKA', web3.utils.toWei('100000'));
    const tokenB = await MockERC20.new('TokenB', 'TKB', web3.utils.toWei('100000'));

    // Uniswap factory
    await deployer.deploy(Factory, admin);
    const factory = await Factory.deployed();

    await factory.createPair(tokenA.address, tokenB.address);


CreatePair function:

function createPair(address tokenA, address tokenB) external override returns (address pair) {
        require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
        require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
        bytes memory bytecode = type(UniswapV2Pair).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token0, token1));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        UniswapV2Pair(pair).initialize(token0, token1); //<-- this is causing the error
        getPair[token0][token1] = pair;
        getPair[token1][token0] = pair; // populate mapping in the reverse direction
        emit PairCreated(token0, token1, pair, allPairs.length);

I have deduced that the error is happening here UniswapV2Pair(pair).initialize(token0, token1); but as to why I have no idea.

Any insights would be much appreciated! James

  • did you manage to sort out this issue? I've run into the same thing May 25, 2021 at 23:15
  • Yes I did actually! You need to find the pairFor function in UniswapV2Library.sol. You then to replace the hex used here with the one generated by your UniswapV2Pair. hex'<YOUR HEX STRING HERE>' // init code hash You can find your bytecode at this line in UniswapV2Factiry.sol bytes memory bytecode = type(UniswapV2Pair).creationCode; I emitted that out to myself and then replaced the hex code and it worked.... I think haha... it was a while ago, but I believe that is the issue :D May 27, 2021 at 14:34

1 Answer 1


Check your truffle config. If you are deploying to testnet or local add the flag

skipDryRun: true

I've deployed the contract to both ropsten and mainnetusing this flag (note: this is default on mainnet)

  • I’m using hardhat instead of truffles. How can I set this flag ? Any idea 💡 thx
    – att
    Jun 17, 2021 at 20:25

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.