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


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)

New contributor
0xHwonderoftheworld is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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